Esempio n. 1
0
/*
 * Class callback when a CPU becomes active (online)
 *
 * This is called in a context where CPUs are paused
 */
static void
pg_cmt_cpu_active(cpu_t *cp)
{
	int		err;
	group_iter_t	i;
	pg_cmt_t	*pg;
	group_t		*pgs;

	ASSERT(MUTEX_HELD(&cpu_lock));

	if (cmt_sched_disabled)
		return;

	pgs = &cp->cpu_pg->pgs;
	group_iter_init(&i);

	/*
	 * Iterate over the CPU's PGs
	 */
	while ((pg = group_iterate(pgs, &i)) != NULL) {

		if (IS_CMT_PG(pg) == 0)
			continue;

		err = group_add(&pg->cmt_cpus_actv, cp, GRP_NORESIZE);
		ASSERT(err == 0);

		/*
		 * If this is the first active CPU in the PG, and it
		 * represents a hardware sharing relationship over which
		 * CMT load balancing is performed, add it as a candidate
		 * for balancing with it's siblings.
		 */
		if (GROUP_SIZE(&pg->cmt_cpus_actv) == 1 &&
		    (pg->cmt_policy & (CMT_BALANCE | CMT_COALESCE))) {
			err = group_add(pg->cmt_siblings, pg, GRP_NORESIZE);
			ASSERT(err == 0);

			/*
			 * If this is a top level PG, add it as a balancing
			 * candidate when balancing within the root lgroup.
			 */
			if (pg->cmt_parent == NULL &&
			    pg->cmt_siblings != &cmt_root->cl_pgs) {
				err = group_add(&cmt_root->cl_pgs, pg,
				    GRP_NORESIZE);
				ASSERT(err == 0);
			}
		}

		/*
		 * Notate the CPU in the PGs active CPU bitset.
		 * Also notate the PG as being active in it's associated
		 * partition
		 */
		bitset_add(&pg->cmt_cpus_actv_set, cp->cpu_seqid);
		bitset_add(&cp->cpu_part->cp_cmt_pgs, ((pg_t *)pg)->pg_id);
	}
}
Esempio n. 2
0
/* Init context bitset for a radio device (hwarc/whci) */
void
uwba_init_ctxt_id(uwba_dev_t *uwba_dev)
{
	bitset_init(&uwba_dev->ctxt_bits); /* this bzero sizeof(bitset_t) */
	bitset_resize(&uwba_dev->ctxt_bits, 256); /* alloc mem */
	bitset_add(&uwba_dev->ctxt_bits, 0);
	bitset_add(&uwba_dev->ctxt_bits, 255);
}
Esempio n. 3
0
int main (int argc, char **argv) {
  int i,j;

  for (i=1; i<SBS_NUM_TESTS; i++) {
    uint32_t nbits = i;
    bitset_set_max_num_elements(nbits);
    printf ("\n\ni=%d nb=%d\n", i, nbits);
    uint32_t num_bs = SBS_NUM_TESTS;
    BitSet *bs;  //  = (BitSet *) my_malloc(sizeof(BitSet) * num_bs);
    bs = bitset_new();
    /*
    for (j=0; j<num_bs; j++) {
      bs[j] = bitset_new();
    }    
    */
    for (j=0; j<nbits * SBS_DUNNO ; j++) {
      printf ("j=%d\n", j);
      int element = rand() % nbits;
      printf ("set %d\n", element);
      bitset_add(bs,element);
      assert (bitset_member(bs,element));
      bitset_spit(bs);
      printf ("\n");
      element = rand() % nbits;
      printf ("unset %d\n", element);
      bitset_remove(bs,element);
      assert (!(bitset_member(bs,element)));
      bitset_spit(bs);
      printf ("\n");
    }
    bitset_free(bs);
  }
}	     
Esempio n. 4
0
/* Get a free context id from bitset */
uint8_t
uwba_get_ctxt_id(uwba_dev_t *uwba_dev)
{
	uint8_t	ctxt_id;

	/* if reaches the top, turn around */
	if (uwba_dev->ctxt_id >= UWB_CTXT_ID_TOP) {
		uwba_dev->ctxt_id = UWB_CTXT_ID_BOTTOM -1;
	}
	ctxt_id = uwba_dev->ctxt_id;

	/* Search ctxt_id+1  to UWB_CTXT_ID_UNVALID */
	do {
		ctxt_id++;

		/* test bit and returen if it is not set */
		if (!bitset_in_set(&uwba_dev->ctxt_bits, ctxt_id)) {
			bitset_add(&uwba_dev->ctxt_bits, ctxt_id);
			uwba_dev->ctxt_id = ctxt_id;

			return (ctxt_id);
		}

	} while (ctxt_id < UWB_CTXT_ID_UNVALID);

	/* Search 1  to ctxt_id */
	if (uwba_dev->ctxt_id != 0) {
		ctxt_id = UWB_CTXT_ID_BOTTOM;
		do {
			ctxt_id++;

			/* test bit and returen if it is not set */
			if (!bitset_in_set(&uwba_dev->ctxt_bits, ctxt_id)) {
				bitset_add(&uwba_dev->ctxt_bits, ctxt_id);
				uwba_dev->ctxt_id = ctxt_id;

				return (ctxt_id);
			}
		} while (ctxt_id < uwba_dev->ctxt_id);
	}

	/* All ids are in use, just force to re-use one. */
	uwba_dev->ctxt_id++;

	return (uwba_dev->ctxt_id);
}
Esempio n. 5
0
// union bsDest with lsSrcs and place result in bsDest
static SB_INLINE void bitset_collect(BitSet *bsDest, BitSet *bsSrc) {
  uint32_t i;
  //if (bsSrc->current_size > 200){
  //    return;
  //}
  for (i=0; i<bsSrc->current_size; i++) {
    bitset_add(bsDest, bsSrc->members[i]);
  }
}
Esempio n. 6
0
/*Parse a string, writting the elements to a bitset
  Return the bitset */
struct bitset * parse_string(char *input){
  struct bitset * result;
  result = bitset_new(256);

  int i;
  for(i =0;input[i] != '\0'; i++){
    bitset_add(result,input[i]);
  }
  return result;
}
Esempio n. 7
0
// add label l to set ls
// NB: this function allocates memory, sometimes, when calling bitset_add.
static SB_INLINE void labelset_add(LabelSet *ls, uint32_t l) {
    bitset_add(*(ls->set), l);
    // NB: we don't set LabelSetType in here.
    // -- could be LST_COPY or LST_COMPUTE after this operation,
    // depending upon what it was before.
    // this is true regardless of previous size of set.
    // we might add a single label to a previously empty set and
    // still want to call the result a copy.
    // assume this is managed at call site or higher up.
}
Esempio n. 8
0
/*
 * Class callback when a CPU is actually moving partitions
 */
static void
pg_cmt_cpupart_move(cpu_t *cp, cpupart_t *oldpp, cpupart_t *newpp)
{
	cpu_t		*cpp;
	group_t		*pgs;
	pg_t		*pg;
	group_iter_t	pg_iter;
	pg_cpu_itr_t	cpu_iter;
	boolean_t	found;

	ASSERT(MUTEX_HELD(&cpu_lock));

	if (cmt_sched_disabled)
		return;

	pgs = &cp->cpu_pg->pgs;
	group_iter_init(&pg_iter);

	/*
	 * Iterate over the CPUs CMT PGs
	 */
	while ((pg = group_iterate(pgs, &pg_iter)) != NULL) {

		if (IS_CMT_PG(pg) == 0)
			continue;

		/*
		 * Add the PG to the bitset in the new partition.
		 */
		bitset_add(&newpp->cp_cmt_pgs, pg->pg_id);

		/*
		 * Remove the PG from the bitset in the old partition
		 * if the last of the PG's CPUs have left.
		 */
		found = B_FALSE;
		PG_CPU_ITR_INIT(pg, cpu_iter);
		while ((cpp = pg_cpu_next(&cpu_iter)) != NULL) {
			if (cpp == cp)
				continue;
			if (CPU_ACTIVE(cpp) &&
			    cpp->cpu_part->cp_id == oldpp->cp_id) {
				found = B_TRUE;
				break;
			}
		}
		if (!found)
			bitset_del(&cp->cpu_part->cp_cmt_pgs, pg->pg_id);
	}
}
int main()
{
    char input1[MAX_SIZE];
    char input2[MAX_SIZE];

    printf("%s\n", "Enter the first line of input:");
    fgets(input1, MAX_SIZE, stdin);

    printf("%s\n", "Enter the second line of input:");
    fgets(input2, MAX_SIZE, stdin);

    struct bitset * set1;
    set1 = bitset_new(MAX_SIZE);

    struct bitset * set2;
    set2 = bitset_new(MAX_SIZE);

    // Create bitsets for the result of
    // union & intersection function calls
    struct bitset * union_result_set;
    union_result_set = bitset_new(MAX_SIZE);

    struct bitset * intersect_result_set;
    intersect_result_set = bitset_new(MAX_SIZE);

    // Can't accept the newline bit, but it was being
    // set each time the fgets call was made and being added

    // Add all the input from string to set1
    for(int i = 0; input1[i] != '\0'; i++){
        if(input1[i] != '\n')
            bitset_add(set1, input1[i]);
    }

    // Add all the input from string to set2
    for(int i = 0; input2[i] != '\0'; i++){
        if(input2[i] != '\n')
            bitset_add(set2, input2[i]);
    }

    bitset_union(union_result_set, set1, set2);

    bitset_intersect(intersect_result_set, set1, set2);

    // Some quick testing I did to make sure things worked
    // Required me to manually enter the desired chars

    // Test adding, removal and lookup
//    printf("Lookup for '2' = %d, expected 1\n", bitset_lookup(set1, '2'));
//    printf("Remove for '2' = %d, expected 1\n", bitset_remove(set1, '2'));
//    printf("Lookup for '2' = %d, expected 0\n", bitset_lookup(set1, '2'));
//
//    printf("Lookup for '3' = %d, expected 1\n", bitset_lookup(set1, '3'));
//    printf("Remove for '3' = %d, expected 1\n", bitset_remove(set1, '3'));
//    printf("Lookup for '3' = %d, expected 0\n", bitset_lookup(set1, '3'));

//     Test union
//    printf("Lookup for '1' = %d, expected 1\n", bitset_lookup(union_result_set, '1'));
//    printf("Lookup for '2' = %d, expected 1\n", bitset_lookup(union_result_set, '2'));
//
//     Test intersection
//    printf("Lookup for '1' = %d, expected 1\n", bitset_lookup(intersect_result_set, '1'));
//    printf("Lookup for '2' = %d, expected 1\n", bitset_lookup(intersect_result_set, '2'));
//    printf("Lookup for '3' = %d, expected 0\n", bitset_lookup(intersect_result_set, '3'));

//    printf("%s\n", "Set 1:");
//    bitset_print(set1);
//
//    printf("%s\n", "Set 2:");
//    bitset_print(set2);
    bitset_print(union_result_set);
    bitset_print(intersect_result_set);

    return 0;
}