#include #include #include #include #include #include #include #include #include int tot_vcpu=0; MD5_CTX mdContext; struct random_vcpu_info{ struct list_head lista; struct vcpu *vcpu; }*runnable; void __init_runnable(void){ runnable=xmalloc(struct random_vcpu_info); INIT_LIST_HEAD(&runnable->lista); printk("\nINIT runnable list\n"); } static int random_vcpu_init(struct vcpu *v){ struct random_vcpu_info *inf; inf= xmalloc(struct random_vcpu_info); if ( inf == NULL ) return -1; INIT_LIST_HEAD(&inf->lista); inf->vcpu=v; runnable->vcpu=v; list_add(&inf->lista,&runnable->lista); tot_vcpu++; printk("\n\nadd VCPU %d\n\n", v->vcpu_id); return 0; } //destroy vcpu struct task_slice random_schedule(s_time_t now){ struct task_slice ret; struct random_vcpu_info *inf; int next_vcpu; printk("\n\nscheduling..\n"); //MD5Final returns a random integer next_vcpu = (MD5Final (&mdContext)) % tot_vcpu; printk("\n\n\nnext_vcpu = %d",next_vcpu); inf = runnable; while (next_vcpu!=0){ inf = list_entry(&runnable->lista, struct random_vcpu_info, lista ); printk("runnable->v =%d", runnable->vcpu->vcpu_id); list_move_tail(&runnable->lista, &runnable->lista); next_vcpu--; printk("\nshifting list\n"); } ret.task= inf->vcpu; ret.time = MILLISECS(10); printk("\n\nI'm scheduling.. vcpi_id=%d , tot_vcpu=%d",inf->vcpu->vcpu_id,tot_vcpu); return ret; } static void __random_init(void){ unsigned char digest[16]; int i; long unsigned int mask= 0xFF; long unsigned int string_now = NOW(); MD5Init (&mdContext); for (i=0;i<8;i++){ digest[i]=(char) ((string_now & mask) >> 8*i); mask <<=8; } printk("Init Random Number Generator with word %x", (unsigned int) digest); MD5Update (&mdContext, (unsigned char*)prova, sizeof(s_time_t)); printk("\n\nUpdating Random Generator\n"); } static void random_vcpu_wake( struct vcpu *vc){ printk("\n\nwake up!!!!!!!!!!!!\n\n"); cpu_raise_softirq(smp_processor_id(),SCHEDULE_SOFTIRQ); __random_init(); return; } struct scheduler sched_random_def = { .name = "my Random Scheduler", .opt_name = "random", .sched_id = 17, .init_vcpu = random_vcpu_init, .wake = random_vcpu_wake, .destroy_vcpu = NULL, .do_schedule = random_schedule, };