예제 #1
0
파일: bitmap-t.c 프로젝트: A-eolus/mysql
my_bool test_intersect(MY_BITMAP *map, uint bitsize)
{
  uint bitsize2 = 1 + get_rand_bit(MAX_TESTED_BITMAP_SIZE - 1);
  MY_BITMAP map2;
  uint32 map2buf[MAX_TESTED_BITMAP_SIZE];
  uint i, test_bit1, test_bit2, test_bit3;
  if (bitmap_init(&map2, map2buf, bitsize2, FALSE))
  {
    diag("init error for bitsize %d", bitsize2);
    return TRUE;
  }
  test_bit1= get_rand_bit(bitsize);
  test_bit2= get_rand_bit(bitsize);
  bitmap_set_bit(map, test_bit1);
  bitmap_set_bit(map, test_bit2);
  test_bit3= get_rand_bit(bitsize2);
  bitmap_set_bit(&map2, test_bit3);
  if (test_bit2 < bitsize2)
    bitmap_set_bit(&map2, test_bit2);

  bitmap_intersect(map, &map2);
  if (test_bit2 < bitsize2)
  {
    if (!bitmap_is_set(map, test_bit2))
      goto error;
    bitmap_clear_bit(map, test_bit2);
  }
  if (test_bit1 == test_bit3)
  {
    if (!bitmap_is_set(map, test_bit1))
      goto error;
    bitmap_clear_bit(map, test_bit1);
  }
  if (!bitmap_is_clear_all(map))
    goto error;

  bitmap_set_all(map);
  bitmap_set_all(&map2);
  for (i=0; i < bitsize2; i++)
    bitmap_clear_bit(&map2, i);
  bitmap_intersect(map, &map2);
  if (!bitmap_is_clear_all(map))
    goto error;
  return FALSE;
error:
  diag("intersect error  bitsize = %u, bit1 = %u, bit2 = %u, bit3 = %u",
       bitsize, test_bit1, test_bit2, test_bit3);
  return TRUE;
}
예제 #2
0
void swap_init(void)
{
	swap_block = block_get_role(BLOCK_SWAP);
	swap_map = bitmap_create(block_size(swap_block)/SECTORS_PER_PAGE);
	bitmap_set_all(swap_map,SWAP_FREE);
	lock_init(&swap_lock);
}
예제 #3
0
파일: swap.c 프로젝트: IVY-bug/Pintos4
void swap_init(void)
{
	swap_disk = disk_get(1,1);
	swap_bitmap = bitmap_create(disk_size(swap_disk)/SECTOR_PER_PAGE);
	
	bitmap_set_all(swap_bitmap, 0);
}
예제 #4
0
/**
 *Initialize the page swapping related data-structures
 */
void initialize_swap_table ()
{
  swap_partition = block_get_role (BLOCK_SWAP);
  lock_init (&swap_lock);
  // Check if no swap partition is available then swapping is disabled
  if (swap_partition == NULL)
  {
    // meaning that swapping is disabled but programs should still run
    // until there is enough physical memory avaiable
    swap_sectors_btmp = bitmap_create (0);
  } else
  {
    // Create bitmap for total number of page swap sectors
    // (i.e. number of sectors rounded to per-page sectors) in swap partition
    // Total number of swap sectors = (total block-size of swap partition)
    //                                /(per page swap sectors)
    swap_sectors_btmp = bitmap_create (
        block_size (swap_partition) / NUM_OF_PER_PAGE_SECTORS);
  }
  // If unable to create swap sectors bitmap, meaning kernel memory is full - PANIL :(
  if (swap_sectors_btmp == NULL)
  {
    PANIC("Swap Sectors bitmap creation failed!!! :(");
  }
  // Reset all bits in this bitmap - to zero
  bitmap_set_all (swap_sectors_btmp, 0);
}
예제 #5
0
파일: bitmap-t.c 프로젝트: A-eolus/mysql
my_bool test_prefix(MY_BITMAP *map, uint bitsize)
{
  uint i, j, test_bit;
  uint no_loops= bitsize > 128 ? 128 : bitsize;
  for (i=0; i < no_loops; i++)
  {
    test_bit=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit);
    if (!bitmap_is_prefix(map, test_bit))
      goto error1;
    bitmap_clear_all(map);
    for (j=0; j < test_bit; j++)
      bitmap_set_bit(map, j);
    if (!bitmap_is_prefix(map, test_bit))
      goto error2;
    bitmap_set_all(map);
    for (j=bitsize - 1; ~(j-test_bit); j--)
      bitmap_clear_bit(map, j);
    if (!bitmap_is_prefix(map, test_bit))
      goto error3;
    bitmap_clear_all(map);
  }
  for (i=0; i < bitsize; i++)
  {
    if (bitmap_is_prefix(map, i + 1))
      goto error4;
    bitmap_set_bit(map, i);
    if (!bitmap_is_prefix(map, i + 1))
      goto error5;
    test_bit=get_rand_bit(bitsize);
    bitmap_set_bit(map, test_bit);
    if (test_bit <= i && !bitmap_is_prefix(map, i + 1))
      goto error5;
    else if (test_bit > i)
    {
      if (bitmap_is_prefix(map, i + 1))
        goto error4;
      bitmap_clear_bit(map, test_bit);
    }
  }
  return FALSE;
error1:
  diag("prefix1 error  bitsize = %u, prefix_size = %u", bitsize,test_bit);
  return TRUE;
error2:
  diag("prefix2 error  bitsize = %u, prefix_size = %u", bitsize,test_bit);
  return TRUE;
error3:
  diag("prefix3 error  bitsize = %u, prefix_size = %u", bitsize,test_bit);
  return TRUE;
error4:
  diag("prefix4 error  bitsize = %u, i = %u", bitsize,i);
  return TRUE;
error5:
  diag("prefix5 error  bitsize = %u, i = %u", bitsize,i);
  return TRUE;
}
예제 #6
0
/* Initializes the inode module. */
void
inode_init (void) 
{
  list_init (&buffcachelist);
  list_init (&open_inodes);
  buffcache = (uint8_t*)malloc(BUFF_CACHE_SIZE);
  cache_bitmap = bitmap_create(N_BUFFERS);
  if(INODE_DEBUG) printf("inode_init(): cache_bitmap NULL! N_BUFFERS: %d init_ram_pages %d \n", N_BUFFERS, 4*(init_ram_pages>>4));
  bitmap_set_all(cache_bitmap, FREE);
}
예제 #7
0
//Initializes swap table
void start_swap (void){
  swap_block = block_get_role (BLOCK_SWAP); //Sets the swap role to block
  if (!swap_block)
      return; //Returns if swap is not blocked
  swap_map = bitmap_create( block_size(swap_block) / SECTORS_PER_PAGE ); //Makes a bitmap for swap
  if (!swap_map)
      return; //Returns if there is no swap map
  bitmap_set_all(swap_map, SWAP_FREE); //Calls bitmap with the map and free arguments for swap
  lock_init(&swap_lock); //Calls the lock intialization with the help of swap lock
}
예제 #8
0
파일: swap.c 프로젝트: Archana16/pintos2
/* Sets up swap. */
void swap_init(void) {
	//block from the swap space
	swap_device = block_get_role(BLOCK_SWAP);
	if (!swap_device) {
		return;
	}
	swap_bitmap = bitmap_create(block_size(swap_device) / SECTORS_PER_PAGE);
	if (!swap_bitmap) {
		return;
	}
	bitmap_set_all(swap_bitmap, SWAP_FREE);
	lock_init(&swap_lock);
}
예제 #9
0
파일: swap.c 프로젝트: linearhw/pintos
/* initialize swap slot */
void vm_swap_init() {
    swap_slot = block_get_role(BLOCK_SWAP);
    if (!swap_slot)
        PANIC("Swap slot is wrong\n");
    
    size_t bit_cnt = block_size(swap_slot) / SECTORS_PER_PAGE;
    swap_partition = bitmap_create(bit_cnt);
    if (!swap_partition)
        PANIC("Swap partition is wrong\n");

    bitmap_set_all(swap_partition, 0);

    lock_init(&swap_lock);
}
예제 #10
0
파일: bitmap-t.c 프로젝트: A-eolus/mysql
my_bool test_get_first_bit(MY_BITMAP *map, uint bitsize)
{
  uint i, test_bit= 0;
  uint no_loops= bitsize > 128 ? 128 : bitsize;

  bitmap_set_all(map);
  for (i=0; i < bitsize; i++)
    bitmap_clear_bit(map, i);
  if (bitmap_get_first_set(map) != MY_BIT_NONE)
    goto error1;
  bitmap_clear_all(map);
  for (i=0; i < bitsize; i++)
    bitmap_set_bit(map, i);
  if (bitmap_get_first(map) != MY_BIT_NONE)
    goto error2;
  bitmap_clear_all(map);

  for (i=0; i < no_loops; i++)
  {
    test_bit=get_rand_bit(bitsize);
    bitmap_set_bit(map, test_bit);
    if (bitmap_get_first_set(map) != test_bit)
      goto error1;
    bitmap_set_all(map);
    bitmap_clear_bit(map, test_bit);
    if (bitmap_get_first(map) != test_bit)
      goto error2;
    bitmap_clear_all(map);
  }
  return FALSE;
error1:
  diag("get_first_set error bitsize=%u,prefix_size=%u",bitsize,test_bit);
  return TRUE;
error2:
  diag("get_first error bitsize= %u, prefix_size= %u",bitsize,test_bit);
  return TRUE;
}
예제 #11
0
void
swap_init (void)
{
  lock_init (&swap_alloc_lock);
  
  swap_block = block_get_role (BLOCK_SWAP);
  if (swap_block != NULL)
    {
      uint32_t page_count = block_size (swap_block) / BLOCKS_PER_PAGE;
      free_blocks = bitmap_create (page_count);
      if (free_blocks == NULL)
        PANIC ("swap_init: unable to create free block bitmap");
      bitmap_set_all (free_blocks, true);
    }
}
예제 #12
0
파일: swap.c 프로젝트: songy23/CS5600
/* Initialize the swap table.
   If fail, panic the kernel. */
void 
swap_table_init () 
{
	swap_block = block_get_role (BLOCK_SWAP);
	if (swap_block == NULL)
	  PANIC ("Fail to allocate swap block");
	block_sector_t blk_size = block_size (swap_block);
	// one sector is 512KB, one swap block is 4096KB so it has 8 sectors
	int slot_size = blk_size / 8;  
	swap_table = bitmap_create (slot_size); 
	if (swap_table == NULL)
	  PANIC ("Fail to allocate swap table");
	bitmap_set_all (swap_table, false);
	lock_init (&swap_table_lock);
}
예제 #13
0
파일: swap.c 프로젝트: songhan/CS140
/* Initialize the swap_table */
void swap_table_init (struct swap_table *swap_table)
{
  lock_init ( &swap_table->lock_bitmap);
  lock_init ( &swap_table->lock_swap);
  swap_table->swap_block = block_get_role ( BLOCK_SWAP );
  block_print_stats ();
  if (swap_table->swap_block)
  {
    int pages_in_swap = 
      block_size (swap_table->swap_block) / SECTORS_PER_PAGE;
    swap_table->bitmap = bitmap_create (pages_in_swap);
    /* False means not occupied */
    bitmap_set_all (swap_table->bitmap, false);
    /* The first frame is reserved for stack growth */
    bitmap_set (swap_table->bitmap, 0, true);
  }
}
예제 #14
0
파일: bitmap-t.c 프로젝트: A-eolus/mysql
my_bool test_get_all_bits(MY_BITMAP *map, uint bitsize)
{
  uint i;
  bitmap_set_all(map);
  if (!bitmap_is_set_all(map))
    goto error1;
  if (!bitmap_is_prefix(map, bitsize))
    goto error5;
  bitmap_clear_all(map);
  if (!bitmap_is_clear_all(map))
    goto error2;
  if (!bitmap_is_prefix(map, 0))
    goto error6;
  for (i=0; i<bitsize;i++)
    bitmap_set_bit(map, i);
  if (!bitmap_is_set_all(map))
    goto error3;
  for (i=0; i<bitsize;i++)
    bitmap_clear_bit(map, i);
  if (!bitmap_is_clear_all(map))
    goto error4;
  return FALSE;
error1:
  diag("Error in set_all, bitsize = %u", bitsize);
  return TRUE;
error2:
  diag("Error in clear_all, bitsize = %u", bitsize);
  return TRUE;
error3:
  diag("Error in bitmap_is_set_all, bitsize = %u", bitsize);
  return TRUE;
error4:
  diag("Error in bitmap_is_clear_all, bitsize = %u", bitsize);
  return TRUE;
error5:
  diag("Error in set_all through set_prefix, bitsize = %u", bitsize);
  return TRUE;
error6:
  diag("Error in clear_all through set_prefix, bitsize = %u", bitsize);
  return TRUE;
}
int
unpack_row_old(Relay_log_info *rli,
               TABLE *table, uint const colcnt, uchar *record,
               uchar const *row, MY_BITMAP const *cols,
               uchar const **row_end, ulong *master_reclength,
               MY_BITMAP* const rw_set, Log_event_type const event_type)
{
  DBUG_ASSERT(record && row);
  my_ptrdiff_t const offset= record - (uchar*) table->record[0];
  size_t master_null_bytes= table->s->null_bytes;

  if (colcnt != table->s->fields)
  {
    Field **fptr= &table->field[colcnt-1];
    do
      master_null_bytes= (*fptr)->last_null_byte();
    while (master_null_bytes == Field::LAST_NULL_BYTE_UNDEF &&
           fptr-- > table->field);

    /*
      If master_null_bytes is LAST_NULL_BYTE_UNDEF (0) at this time,
      there were no nullable fields nor BIT fields at all in the
      columns that are common to the master and the slave. In that
      case, there is only one null byte holding the X bit.

      OBSERVE! There might still be nullable columns following the
      common columns, so table->s->null_bytes might be greater than 1.
     */
    if (master_null_bytes == Field::LAST_NULL_BYTE_UNDEF)
      master_null_bytes= 1;
  }

  DBUG_ASSERT(master_null_bytes <= table->s->null_bytes);
  memcpy(record, row, master_null_bytes);            // [1]
  int error= 0;

  bitmap_set_all(rw_set);

  Field **const begin_ptr = table->field;
  Field **field_ptr;
  uchar const *ptr= row + master_null_bytes;
  Field **const end_ptr= begin_ptr + colcnt;
  for (field_ptr= begin_ptr ; field_ptr < end_ptr ; ++field_ptr)
  {
    Field *const f= *field_ptr;

    if (bitmap_is_set(cols, field_ptr -  begin_ptr))
    {
      f->move_field_offset(offset);
      ptr= f->unpack(f->ptr, ptr);
      f->move_field_offset(-offset);
      /* Field...::unpack() cannot return 0 */
      DBUG_ASSERT(ptr != NULL);
    }
    else
      bitmap_clear_bit(rw_set, field_ptr - begin_ptr);
  }

  *row_end = ptr;
  if (master_reclength)
  {
    if (*field_ptr)
      *master_reclength = (*field_ptr)->ptr - table->record[0];
    else
      *master_reclength = table->s->reclength;
  }

  /*
    Set properties for remaining columns, if there are any. We let the
    corresponding bit in the write_set be set, to write the value if
    it was not there already. We iterate over all remaining columns,
    even if there were an error, to get as many error messages as
    possible.  We are still able to return a pointer to the next row,
    so redo that.

    This generation of error messages is only relevant when inserting
    new rows.
   */
  for ( ; *field_ptr ; ++field_ptr)
  {
    uint32 const mask= NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG;

    DBUG_PRINT("debug", ("flags = 0x%x, mask = 0x%x, flags & mask = 0x%x",
                         (*field_ptr)->flags, mask,
                         (*field_ptr)->flags & mask));

    if (event_type == WRITE_ROWS_EVENT &&
        ((*field_ptr)->flags & mask) == mask)
    {
      rli->report(ERROR_LEVEL, ER_NO_DEFAULT_FOR_FIELD,
                  "Field `%s` of table `%s`.`%s` "
                  "has no default value and cannot be NULL",
                  (*field_ptr)->field_name, table->s->db.str,
                  table->s->table_name.str);
      error = ER_NO_DEFAULT_FOR_FIELD;
    }
    else
      (*field_ptr)->set_default();
  }

  return error;
}
예제 #16
0
파일: bitmap-t.c 프로젝트: A-eolus/mysql
my_bool test_compare_operators(MY_BITMAP *map, uint bitsize)
{
  uint i, j, test_bit1, test_bit2, test_bit3,test_bit4;
  uint no_loops= bitsize > 128 ? 128 : bitsize;
  MY_BITMAP map2_obj, map3_obj;
  MY_BITMAP *map2= &map2_obj, *map3= &map3_obj;
  uint32 map2buf[MAX_TESTED_BITMAP_SIZE];
  uint32 map3buf[MAX_TESTED_BITMAP_SIZE];
  bitmap_init(&map2_obj, map2buf, bitsize, FALSE);
  bitmap_init(&map3_obj, map3buf, bitsize, FALSE);
  bitmap_clear_all(map2);
  bitmap_clear_all(map3);
  for (i=0; i < no_loops; i++)
  {
    test_bit1=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit1);
    test_bit2=get_rand_bit(bitsize);
    bitmap_set_prefix(map2, test_bit2);
    bitmap_intersect(map, map2);
    test_bit3= test_bit2 < test_bit1 ? test_bit2 : test_bit1;
    bitmap_set_prefix(map3, test_bit3);
    if (!bitmap_cmp(map, map3))
      goto error1;
    bitmap_clear_all(map);
    bitmap_clear_all(map2);
    bitmap_clear_all(map3);
    test_bit1=get_rand_bit(bitsize);
    test_bit2=get_rand_bit(bitsize);
    test_bit3=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit1);
    bitmap_set_prefix(map2, test_bit2);
    test_bit3= test_bit2 > test_bit1 ? test_bit2 : test_bit1;
    bitmap_set_prefix(map3, test_bit3);
    bitmap_union(map, map2);
    if (!bitmap_cmp(map, map3))
      goto error2;
    bitmap_clear_all(map);
    bitmap_clear_all(map2);
    bitmap_clear_all(map3);
    test_bit1=get_rand_bit(bitsize);
    test_bit2=get_rand_bit(bitsize);
    test_bit3=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit1);
    bitmap_set_prefix(map2, test_bit2);
    bitmap_xor(map, map2);
    test_bit3= test_bit2 > test_bit1 ? test_bit2 : test_bit1;
    test_bit4= test_bit2 < test_bit1 ? test_bit2 : test_bit1;
    bitmap_set_prefix(map3, test_bit3);
    for (j=0; j < test_bit4; j++)
      bitmap_clear_bit(map3, j);
    if (!bitmap_cmp(map, map3))
      goto error3;
    bitmap_clear_all(map);
    bitmap_clear_all(map2);
    bitmap_clear_all(map3);
    test_bit1=get_rand_bit(bitsize);
    test_bit2=get_rand_bit(bitsize);
    test_bit3=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit1);
    bitmap_set_prefix(map2, test_bit2);
    bitmap_subtract(map, map2);
    if (test_bit2 < test_bit1)
    {
      bitmap_set_prefix(map3, test_bit1);
      for (j=0; j < test_bit2; j++)
        bitmap_clear_bit(map3, j);
    }
    if (!bitmap_cmp(map, map3))
      goto error4;
    bitmap_clear_all(map);
    bitmap_clear_all(map2);
    bitmap_clear_all(map3);
    test_bit1=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit1);
    bitmap_invert(map);
    bitmap_set_all(map3);
    for (j=0; j < test_bit1; j++)
      bitmap_clear_bit(map3, j);
    if (!bitmap_cmp(map, map3))
      goto error5;
    bitmap_clear_all(map);
    bitmap_clear_all(map3);
  }
  return FALSE;
error1:
  diag("intersect error  bitsize=%u,size1=%u,size2=%u", bitsize,
  test_bit1,test_bit2);
  return TRUE;
error2:
  diag("union error  bitsize=%u,size1=%u,size2=%u", bitsize,
  test_bit1,test_bit2);
  return TRUE;
error3:
  diag("xor error  bitsize=%u,size1=%u,size2=%u", bitsize,
  test_bit1,test_bit2);
  return TRUE;
error4:
  diag("subtract error  bitsize=%u,size1=%u,size2=%u", bitsize,
  test_bit1,test_bit2);
  return TRUE;
error5:
  diag("invert error  bitsize=%u,size=%u", bitsize,
  test_bit1);
  return TRUE;
}