Index: 2.6.12-genetic/include/linux/sched.h =================================================================== --- 2.6.12-genetic.orig/include/linux/sched.h 2005-08-15 16:16:26.000000000 -0500 +++ 2.6.12-genetic/include/linux/sched.h 2005-08-15 16:18:21.000000000 -0500 @@ -143,6 +143,20 @@ #include /* + * These are the 'tuning knobs' of the scheduler: + * + * Default configurable timeslice is 100 msecs, maximum configurable + * timeslice is 1000 msecs and minumum configurable timeslice is 1 jiffy. + * Timeslices get renewed on task creation, on wake up and after they expire. + */ +#define MIN_TIMESLICE 1 +#define DEF_TIMESLICE (10 * HZ / 1000) +#define MAX_TIMESLICE (1000 * HZ / 1000) +#define DEF_DESKTOP_TIMESLICE ((DEF_TIMESLICE > 10) ? (DEF_TIMESLICE / 10) : 1) + +#define DEFAULT_UNPRIV_RT_THRESHOLD 10 + +/* * This serializes "schedule()" and also protects * the run-queue from deletions/modifications (but * _adding_ to the beginning of the run-queue has @@ -590,7 +604,8 @@ unsigned long policy; cpumask_t cpus_allowed; - + unsigned long time_slice_ran; + #ifdef CONFIG_SCHEDSTATS struct sched_info sched_info; #endif @@ -852,6 +867,8 @@ extern int sched_setscheduler(struct task_struct *, int, struct sched_param *); extern task_t *idle_task(int cpu); +extern void genetic_cpu_sched_init(void); + void yield(void); /* @@ -1231,8 +1248,6 @@ } #endif -extern long sched_setaffinity(pid_t pid, cpumask_t new_mask); -extern long sched_getaffinity(pid_t pid, cpumask_t *mask); #ifdef CONFIG_MAGIC_SYSRQ Index: 2.6.12-genetic/kernel/sched.c =================================================================== --- 2.6.12-genetic.orig/kernel/sched.c 2005-08-15 16:16:26.000000000 -0500 +++ 2.6.12-genetic/kernel/sched.c 2005-08-15 16:18:21.000000000 -0500 @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -2084,6 +2085,22 @@ #ifdef __ARCH_WANT_SYS_NICE +#ifdef CONFIG_GENETIC_ZAPHOD_CPU_SCHED +#if 0 +/* XXX fix me!!! */ +static inline void genetic_fixup_timeslice(task_t * p) +{ + unsigned long tmp_timeslice = task_timeslice(p); + + if (p->time_slice > tmp_timeslice) + p->time_slice = tmp_timeslice; + + if (++p->time_slice_ran > tmp_timeslice) + p->time_slice = 1; +} +#endif +#endif + /* * sys_nice - change the priority of the current process. * @increment: priority increment Index: 2.6.12-genetic/kernel/sched_zaphod.c =================================================================== --- 2.6.12-genetic.orig/kernel/sched_zaphod.c 2005-08-15 16:17:58.000000000 -0500 +++ 2.6.12-genetic/kernel/sched_zaphod.c 2005-08-17 14:01:27.000000000 -0500 @@ -21,6 +21,8 @@ */ #include #include +#include +#include #include @@ -79,11 +81,20 @@ #define MAX_TOTAL_BONUS (BGND_PRIO - ZAPHOD_MAX_PRIO - 1) #define MAX_MAX_IA_BONUS ((MAX_TOTAL_BONUS + 1) / 2) #define MAX_MAX_TPT_BONUS (MAX_TOTAL_BONUS - MAX_MAX_IA_BONUS) -#define DEFAULT_MAX_IA_BONUS ((MAX_MAX_IA_BONUS < 9) ? MAX_MAX_IA_BONUS : 9) -#define DEFAULT_MAX_TPT_BONUS ((DEFAULT_MAX_IA_BONUS - 2) ? : 1) +#if MAX_MAX_IA_BONUS < 9 +#define DEFAULT_MAX_IA_BONUS MAX_MAX_IA_BONUS +#else +#define DEFAULT_MAX_IA_BONUS 9 +#endif + +#if DEFAULT_MAX_IA_BONUS == 2 +#define DEFAULT_MAX_TPT_BONUS 1 +#else +#define DEFAULT_MAX_TPT_BONUS 0 +#endif -#define SCHED_IA_BONUS_OFFSET 8 +#define SCHED_IA_BONUS_OFFSET 7 #define SCHED_IA_BONUS_ALPHA ((1 << SCHED_IA_BONUS_OFFSET) - 1) #define SCHED_IA_BONUS_MUL(a, b) (((a) * (b)) >> SCHED_IA_BONUS_OFFSET) /* @@ -468,3 +479,591 @@ .show = show_zaphod_mode, .store = store_zaphod_mode, }; + + +#ifdef CONFIG_GENETIC_ZAPHOD_CPU_SCHED + +extern unsigned long sched_rr_time_slice; +extern unsigned long time_slice; +extern unsigned long base_prom_interval; +extern unsigned int bgnd_time_slice_multiplier; +static void zaphod_rt_create_child(genetic_child_t *); +static void zaphod_intr_create_child(genetic_child_t *); +static void zaphod_fork_create_child(genetic_child_t *); +static void zaphod_total_delay_create_child(genetic_child_t *); +static void zaphod_context_switches_create_child(genetic_child_t *); +static void zaphod_latency_create_child(genetic_child_t *); +static void zaphod_general_create_child(genetic_child_t *); +static void zaphod_shift_mutation_rate(phenotype_t * in_pt); + +void zaphod_rt_set_child_genes(void *); +void zaphod_intr_set_child_genes(void *); +void zaphod_fork_set_child_genes(void *); +void zaphod_general_set_child_genes(void *); + +void zaphod_rt_calc_fitness(genetic_child_t *); +void zaphod_intr_calc_fitness(genetic_child_t *); +void zaphod_fork_calc_fitness(genetic_child_t *); +void zaphod_total_delay_calc_fitness(genetic_child_t *); +void zaphod_latency_calc_fitness(genetic_child_t *); +void zaphod_context_switches_calc_fitness(genetic_child_t *); + +void zaphod_general_calc_post_fitness(phenotype_t *); + +void zaphod_general_take_snapshot(phenotype_t *); + +/* For real-time tasks */ +struct genetic_ops zaphod_rt_genetic_ops = { + .create_child = zaphod_rt_create_child, + .set_child_genes = zaphod_rt_set_child_genes, + .calc_fitness = zaphod_rt_calc_fitness, + .combine_genes = genetic_generic_combine_genes, + .mutate_child = genetic_generic_mutate_child, +}; + +/* For interactivity */ +struct genetic_ops zaphod_intr_genetic_ops = { + .create_child = zaphod_intr_create_child, + .set_child_genes = zaphod_intr_set_child_genes, + .calc_fitness = zaphod_intr_calc_fitness, + .combine_genes = genetic_generic_combine_genes, + .mutate_child = genetic_generic_mutate_child, +}; + +#define MODIFY_INITIAL_IA_BONUS 1 + +#if MODIFY_INITIAL_IA_BONUS +/* For new processes */ +struct genetic_ops zaphod_fork_genetic_ops = { + .create_child = zaphod_fork_create_child, + .set_child_genes = zaphod_fork_set_child_genes, + .calc_fitness = zaphod_fork_calc_fitness, + .combine_genes = genetic_generic_combine_genes, + .mutate_child = genetic_generic_mutate_child, +}; +#else +/* For new processes */ +struct genetic_ops zaphod_fork_genetic_ops = { + .create_child = zaphod_fork_create_child, + .calc_fitness = zaphod_fork_calc_fitness, +}; +#endif + +/* For total delay */ +struct genetic_ops zaphod_total_delay_genetic_ops = { + .create_child = zaphod_total_delay_create_child, + .calc_fitness = zaphod_total_delay_calc_fitness, +}; + +/* For context switches */ +struct genetic_ops zaphod_context_switches_genetic_ops = { + .create_child = zaphod_context_switches_create_child, + .calc_fitness = zaphod_context_switches_calc_fitness, +}; + +/* For latency */ +struct genetic_ops zaphod_latency_genetic_ops = { + .create_child = zaphod_latency_create_child, + .calc_fitness = zaphod_latency_calc_fitness, +}; + +/* For general genes */ +struct genetic_ops zaphod_general_genetic_ops = { + .create_child = zaphod_general_create_child, + .set_child_genes = zaphod_general_set_child_genes, + .combine_genes = genetic_generic_combine_genes, + .mutate_child = genetic_generic_mutate_child, + .calc_post_fitness = zaphod_general_calc_post_fitness, + .take_snapshot = zaphod_general_take_snapshot, + .shift_mutation_rate = zaphod_shift_mutation_rate +}; + +#define ZAPHOD_RT_UID 1 +#define ZAPHOD_RT_NUM_GENES 1 +gene_param_t zaphod_rt_gene_param[ZAPHOD_RT_NUM_GENES] = { + { MIN_TIMESLICE, MAX_TIMESLICE, (100 * HZ / 1000), 0 }, /* sched_rr_time_slice */ +}; + +#define ZAPHOD_INTR_UID 2 +#define ZAPHOD_INTR_NUM_GENES 2 +#if 1 +gene_param_t zaphod_intr_gene_param[ZAPHOD_INTR_NUM_GENES] = { + { 0, 1000, DEFAULT_IA_THRESHOLD, genetic_generic_iterative_mutate_gene }, /* ia_threshold */ + { 0, 1000, DEFAULT_CPU_HOG_THRESHOLD, genetic_generic_iterative_mutate_gene }, /* cpu_hog_threshold */ +}; +#else +gene_param_t zaphod_intr_gene_param[ZAPHOD_INTR_NUM_GENES] = { + { 0, 1000, DEFAULT_IA_THRESHOLD, 0 }, /* ia_threshold */ + { 0, 1000, DEFAULT_CPU_HOG_THRESHOLD, 0 }, /* cpu_hog_threshold */ +}; +#endif + +#define ZAPHOD_FORK_UID 4 +#if MODIFY_INITIAL_IA_BONUS +#define ZAPHOD_FORK_NUM_GENES 1 +#else +#define ZAPHOD_FORK_NUM_GENES 0 +#endif +gene_param_t zaphod_fork_gene_param[ZAPHOD_FORK_NUM_GENES] = { + { 0, MAX_MAX_IA_BONUS, 1, 0 }, /* initial_ia_bonus */ +}; + +#define ZAPHOD_TOTAL_DELAY_UID 8 +#define ZAPHOD_TOTAL_DELAY_NUM_GENES 0 + +#define ZAPHOD_CONTEXT_SWITCHES_UID 16 +#define ZAPHOD_CONTEXT_SWITCHES_NUM_GENES 0 + +#define ZAPHOD_LATENCY_UID 32 +#define ZAPHOD_LATENCY_NUM_GENES 0 + +#define ZAPHOD_GENERAL_UID (ZAPHOD_CONTEXT_SWITCHES_UID | ZAPHOD_TOTAL_DELAY_UID | ZAPHOD_INTR_UID | ZAPHOD_RT_UID | ZAPHOD_LATENCY_UID) +#define ZAPHOD_GENERAL_NUM_GENES 5 +#if 0 +gene_param_t zaphod_general_gene_param[ZAPHOD_GENERAL_NUM_GENES] = { + { MIN_TIMESLICE, MAX_TIMESLICE, DEF_TIMESLICE, genetic_generic_iterative_mutate_gene }, /* time_slice */ + { 0, MAX_MAX_IA_BONUS, DEFAULT_MAX_IA_BONUS, 0 }, /* max_ia_bonus */ + { 0, MAX_MAX_TPT_BONUS, DEFAULT_MAX_TPT_BONUS, 0 }, /* max_tpt_bonus */ + { 1, 100, 1, genetic_generic_iterative_mutate_gene }, /* bgnd_time_slice_multiplier */ + { 0, 1, 0, 0 }, /* zaphod_mode */ +}; +#else +gene_param_t zaphod_general_gene_param[ZAPHOD_GENERAL_NUM_GENES] = { + { MIN_TIMESLICE, MAX_TIMESLICE, DEF_TIMESLICE, 0 }, /* time_slice */ + { 0, MAX_MAX_IA_BONUS, DEFAULT_MAX_IA_BONUS, 0 }, /* max_ia_bonus */ + { 0, MAX_MAX_TPT_BONUS, DEFAULT_MAX_TPT_BONUS, 0 }, /* max_tpt_bonus */ + { 1, 100, 1, genetic_generic_iterative_mutate_gene }, /* bgnd_time_slice_multiplier */ + { 0, 1, 0, 0 }, /* zaphod_mode */ +}; +#endif + +struct zaphod_stats_snapshot * zaphod_stats_snapshot; + +static int __init genetic_zaphod_sched_init(void) +{ + genetic_t * genetic = 0; + + zaphod_stats_snapshot = (struct zaphod_stats_snapshot *)kmalloc(sizeof(struct zaphod_stats_snapshot), GFP_KERNEL); + if (!zaphod_stats_snapshot) + panic("zaphod sched: failed to malloc enough space"); + + if(genetic_init(&genetic, ZAPHOD_SCHED_NUM_CHILDREN, ZAPHOD_SCHED_CHILD_LIFESPAN, + "zaphod-sched")) + panic("zaphod sched: failed to init genetic lib"); + + if(genetic_register_phenotype(genetic, &zaphod_rt_genetic_ops, ZAPHOD_SCHED_NUM_CHILDREN, + "real-time-tasks", ZAPHOD_RT_NUM_GENES, ZAPHOD_RT_UID)) + panic("zaphod sched: failed to register real-time tasks phenotype"); + + if(genetic_register_phenotype(genetic, &zaphod_intr_genetic_ops, ZAPHOD_SCHED_NUM_CHILDREN, + "interactiveness", ZAPHOD_INTR_NUM_GENES, ZAPHOD_INTR_UID)) + panic("zaphod sched: failed to register interactiveness phenotype"); + + if(genetic_register_phenotype(genetic, &zaphod_fork_genetic_ops, ZAPHOD_SCHED_NUM_CHILDREN, + "initial-interactiveness", ZAPHOD_FORK_NUM_GENES, ZAPHOD_FORK_UID)) + panic("zaphod sched: failed to register initial-interactiveness phenotype"); + + if(genetic_register_phenotype(genetic, &zaphod_total_delay_genetic_ops, ZAPHOD_SCHED_NUM_CHILDREN, + "total-delay", ZAPHOD_TOTAL_DELAY_NUM_GENES, ZAPHOD_TOTAL_DELAY_UID)) + panic("zaphod sched: failed to register total-delay phenotype"); + + if(genetic_register_phenotype(genetic, &zaphod_context_switches_genetic_ops, ZAPHOD_SCHED_NUM_CHILDREN, + "context-switches", ZAPHOD_CONTEXT_SWITCHES_NUM_GENES, ZAPHOD_CONTEXT_SWITCHES_UID)) + panic("zaphod sched: failed to register context-switches phenotype"); + + if(genetic_register_phenotype(genetic, &zaphod_latency_genetic_ops, ZAPHOD_SCHED_NUM_CHILDREN, + "latency", ZAPHOD_LATENCY_NUM_GENES, ZAPHOD_LATENCY_UID)) + panic("zaphod sched: failed to register latency phenotype"); + + if(genetic_register_phenotype(genetic, &zaphod_general_genetic_ops, ZAPHOD_SCHED_NUM_CHILDREN, + "general", ZAPHOD_GENERAL_NUM_GENES, ZAPHOD_GENERAL_UID)) + panic("zaphod sched: failed to register general phenotype"); + + genetic_start(genetic); + + return 0; +} + +void zaphod_rt_create_child(genetic_child_t * child) +{ + BUG_ON(!child); + + child->genes = (void *)kmalloc(sizeof(struct zaphod_rt_genes), GFP_KERNEL); + if (!child->genes) + panic("zaphod_rt_create_child: error kmalloc'n space"); + + child->gene_param = zaphod_rt_gene_param; + child->num_genes = ZAPHOD_RT_NUM_GENES; + child->stats_snapshot = zaphod_stats_snapshot; + + genetic_create_child_spread(child, ZAPHOD_SCHED_NUM_CHILDREN); +// genetic_create_child_defaults(child); + +} + +void zaphod_intr_create_child(genetic_child_t * child) +{ + BUG_ON(!child); + + child->genes = (void *)kmalloc(sizeof(struct zaphod_intr_genes), GFP_KERNEL); + if (!child->genes) + panic("zaphod_intr_create_child: error kmalloc'n space"); + + child->gene_param = zaphod_intr_gene_param; + child->num_genes = ZAPHOD_INTR_NUM_GENES; + child->stats_snapshot = zaphod_stats_snapshot; + + genetic_create_child_spread(child, ZAPHOD_SCHED_NUM_CHILDREN); +// genetic_create_child_defaults(child); +} + +#if MODIFY_INITIAL_IA_BONUS +void zaphod_fork_create_child(genetic_child_t * child) +{ + BUG_ON(!child); + + child->genes = (void *)kmalloc(sizeof(struct zaphod_fork_genes), GFP_KERNEL); + if (!child->genes) + panic("zaphod_fork_create_child: error kmalloc'n space"); + + child->gene_param = zaphod_fork_gene_param; + child->num_genes = ZAPHOD_FORK_NUM_GENES; + child->stats_snapshot = zaphod_stats_snapshot; + + genetic_create_child_spread(child, ZAPHOD_SCHED_NUM_CHILDREN); +// genetic_create_child_defaults(child); +} +#else +void zaphod_fork_create_child(genetic_child_t * child) +{ + BUG_ON(!child); + + child->genes = 0; + child->gene_param = 0; + child->num_genes = 0; + child->stats_snapshot = zaphod_stats_snapshot; +} +#endif + +void zaphod_total_delay_create_child(genetic_child_t * child) +{ + BUG_ON(!child); + + child->genes = 0; + child->gene_param = 0; + child->num_genes = 0; + child->stats_snapshot = zaphod_stats_snapshot; +} + +void zaphod_context_switches_create_child(genetic_child_t * child) +{ + BUG_ON(!child); + + child->genes = 0; + child->gene_param = 0; + child->num_genes = 0; + child->stats_snapshot = zaphod_stats_snapshot; +} + +void zaphod_latency_create_child(genetic_child_t * child) +{ + BUG_ON(!child); + + child->genes = 0; + child->gene_param = 0; + child->num_genes = 0; + child->stats_snapshot = zaphod_stats_snapshot; +} + +void zaphod_general_create_child(genetic_child_t * child) +{ + BUG_ON(!child); + + child->genes = (void *)kmalloc(sizeof(struct zaphod_general_genes), GFP_KERNEL); + if (!child->genes) + panic("zaphod_general_create_child: error kmalloc'n space"); + + child->gene_param = zaphod_general_gene_param; + child->num_genes = ZAPHOD_GENERAL_NUM_GENES; + child->stats_snapshot = zaphod_stats_snapshot; + + genetic_create_child_spread(child, ZAPHOD_SCHED_NUM_CHILDREN); +// genetic_create_child_defaults(child); +} + + +static void zaphod_shift_mutation_rate(phenotype_t * in_pt) +{ + struct list_head * p; + phenotype_t * pt; + int count = 0; + long rate = 0; + + list_for_each(p, &in_pt->genetic->phenotype) { + pt = list_entry(p, phenotype_t, phenotype); + + /* Look at everyone else that contributes to this + phenotype */ + if (pt->uid & ZAPHOD_GENERAL_UID && pt->uid != ZAPHOD_GENERAL_UID) { + + switch (pt->uid) { + case ZAPHOD_RT_UID: + break; + case ZAPHOD_CONTEXT_SWITCHES_UID: + case ZAPHOD_LATENCY_UID: + break; + case ZAPHOD_INTR_UID: + case ZAPHOD_TOTAL_DELAY_UID: + rate += pt->mutation_rate; + count++; + break; + default: + BUG(); + } + } + } + + /* If we are a general phenotype that is made up of other + phenotypes then we take the average */ + if (count) + in_pt->mutation_rate = (rate / count); + else + BUG(); +} + + +/* Make the general the one that takes into account all the fitness + * routines, since these are the common genes that effect everything. + */ +void zaphod_general_calc_post_fitness(phenotype_t * in_pt) +{ + struct list_head * p; + phenotype_t * pt; + genetic_t * genetic = in_pt->genetic; + int ranking[ZAPHOD_SCHED_NUM_CHILDREN]; + int weight = 1; + int i; + + memset(ranking, 0, sizeof(ranking)); + + list_for_each(p, &genetic->phenotype) { + pt = list_entry(p, phenotype_t, phenotype); + + /* Look at everyone else that contributes to this + phenotype */ + if (pt->uid & ZAPHOD_GENERAL_UID && pt->uid != ZAPHOD_GENERAL_UID) { + + switch (pt->uid) { + case ZAPHOD_RT_UID: + case ZAPHOD_CONTEXT_SWITCHES_UID: + case ZAPHOD_LATENCY_UID: + weight = 1; + break; + case ZAPHOD_INTR_UID: + weight = 2; + break; + case ZAPHOD_TOTAL_DELAY_UID: + weight = 3; + break; + default: + BUG(); + } + + for (i = 0; i < pt->num_children; i++) + ranking[pt->child_ranking[i]->id] += (i * weight); + } + } + + for (i = 0; i < in_pt->num_children; i++) + in_pt->child_ranking[i]->fitness = ranking[i]; + +} + +core_initcall(genetic_zaphod_sched_init); + + +extern unsigned int max_ia_bonus; +extern unsigned long ia_threshold; +extern unsigned long cpu_hog_threshold; +extern unsigned int initial_ia_bonus; +extern unsigned int max_tpt_bonus; +extern enum zaphod_mode_enum zaphod_mode; + +void zaphod_rt_set_child_genes(void * in_genes) +{ + struct zaphod_rt_genes * genes = (struct zaphod_rt_genes *)in_genes; + + sched_rr_time_slice = genes->sched_rr_time_slice; +} + +void zaphod_intr_set_child_genes(void * in_genes) +{ + struct zaphod_intr_genes * genes = (struct zaphod_intr_genes *)in_genes; + + ia_threshold = ppt_to_proportion(genes->ia_threshold); + cpu_hog_threshold = ppt_to_proportion(genes->cpu_hog_threshold); +} + +void zaphod_fork_set_child_genes(void * in_genes) +{ + struct zaphod_fork_genes * genes = (struct zaphod_fork_genes *)in_genes; + + initial_ia_bonus = genes->initial_ia_bonus; +} + +void zaphod_general_set_child_genes(void * in_genes) +{ + struct zaphod_general_genes * genes = (struct zaphod_general_genes *)in_genes; + + time_slice = genes->time_slice; + base_prom_interval = ((time_slice * 15) / 10); + max_ia_bonus = genes->max_ia_bonus; + max_tpt_bonus = genes->max_tpt_bonus; + bgnd_time_slice_multiplier = genes->bgnd_time_slice_multiplier; + zaphod_mode = genes->zaphod_mode; + +} + +/* Just have the general phenotype take the whole snapshot */ +void zaphod_general_take_snapshot(phenotype_t * pt) +{ + struct runq_cpustats * csrq; + struct zaphod_stats_snapshot * ss = (struct zaphod_stats_snapshot *)pt->child_ranking[0]->stats_snapshot; +#ifdef CONFIG_SCHEDSTATS + runqueue_t * rq; +#endif + int cpu; + + memset(ss, 0, sizeof(struct zaphod_stats_snapshot)); + + /* Get snapshot for this child */ + for_each_online_cpu(cpu) { + csrq = cpu_runq_cpustats(cpu); + + ss->total_delay += csrq->total_delay; + ss->total_rt_delay += csrq->total_rt_delay; + ss->total_intr_delay += csrq->total_intr_delay; + ss->total_rt_intr_delay += csrq->total_rt_intr_delay; + ss->total_latency += csrq->total_latency; + ss->total_fork_delay += csrq->total_fork_delay; + + } + +#ifdef CONFIG_SCHEDSTATS + for_each_online_cpu(cpu) { + rq = cpu_rq(cpu); + + ss->cpu_time += rq->rq_sched_info.cpu_time; + ss->run_delay += rq->rq_sched_info.run_delay; + } +#endif + + ss->nr_switches += nr_context_switches(); + + + +} + +void zaphod_rt_calc_fitness(genetic_child_t * child) +{ + + struct zaphod_stats_snapshot * ss = (struct zaphod_stats_snapshot *)child->stats_snapshot; + struct runq_cpustats *csrq; + long long total_rt_delay = 0; + int cpu; + + for_each_online_cpu(cpu) { + csrq = cpu_runq_cpustats(cpu); + + total_rt_delay += csrq->total_rt_delay; + } + child->fitness = -(total_rt_delay - ss->total_rt_delay); + +} + +void zaphod_intr_calc_fitness(genetic_child_t * child) +{ + struct zaphod_stats_snapshot * ss = (struct zaphod_stats_snapshot *)child->stats_snapshot; + struct runq_cpustats *csrq; + long long total_intr_delay = 0; + int cpu; + + for_each_online_cpu(cpu) { + csrq = cpu_runq_cpustats(cpu); + + total_intr_delay += csrq->total_intr_delay; + } + child->fitness = -(total_intr_delay - ss->total_intr_delay); + +} + +void zaphod_fork_calc_fitness(genetic_child_t * child) +{ + struct zaphod_stats_snapshot * ss = (struct zaphod_stats_snapshot *)child->stats_snapshot; + struct runq_cpustats *csrq; + long long total_fork_delay = 0; + int cpu; + + for_each_online_cpu(cpu) { + csrq = cpu_runq_cpustats(cpu); + + total_fork_delay += csrq->total_fork_delay; + } + child->fitness = -(total_fork_delay - ss->total_fork_delay); + +} + +void zaphod_latency_calc_fitness(genetic_child_t * child) +{ + struct zaphod_stats_snapshot * ss = (struct zaphod_stats_snapshot *)child->stats_snapshot; + struct runq_cpustats *csrq; + long long total_latency = 0; + int cpu; + + for_each_online_cpu(cpu) { + csrq = cpu_runq_cpustats(cpu); + + total_latency += csrq->total_latency; + } + child->fitness = -(total_latency - ss->total_latency); + +} + +void zaphod_total_delay_calc_fitness(genetic_child_t * child) +{ + struct zaphod_stats_snapshot * ss = (struct zaphod_stats_snapshot *)child->stats_snapshot; + struct runq_cpustats *csrq; + long long total_delay = 0; + long long total_rt_delay = 0; + long long total_intr_delay = 0; + long long total_rt_intr_delay = 0; + int cpu; + + for_each_online_cpu(cpu) { + csrq = cpu_runq_cpustats(cpu); + + total_delay += csrq->total_delay; + total_intr_delay += csrq->total_intr_delay; + total_rt_delay += csrq->total_rt_delay; + total_rt_intr_delay += csrq->total_rt_intr_delay; + } + + /* get delta */ + total_delay -= ss->total_delay; + total_rt_delay -= ss->total_rt_delay; + total_intr_delay -= ss->total_intr_delay; + total_rt_intr_delay -= ss->total_rt_intr_delay; + + child->fitness = -(total_delay - total_rt_delay - (total_intr_delay - total_rt_intr_delay)); + +} + +void zaphod_context_switches_calc_fitness(genetic_child_t * child) +{ + struct zaphod_stats_snapshot * ss = (struct zaphod_stats_snapshot *)child->stats_snapshot; + + child->fitness = -(nr_context_switches() - ss->nr_switches); +} + +#endif /* CONFIG_GENETIC_ZAPHOD_CPU_SCHED */ + Index: 2.6.12-genetic/lib/Kconfig =================================================================== --- 2.6.12-genetic.orig/lib/Kconfig 2005-08-15 16:16:26.000000000 -0500 +++ 2.6.12-genetic/lib/Kconfig 2005-08-15 16:18:21.000000000 -0500 @@ -36,6 +36,14 @@ This option will build in a genetic library that will tweak kernel parameters autonomically to improve performance. +config GENETIC_ZAPHOD_CPU_SCHED + bool "Genetic Library - Zaphod CPU scheduler" + depends on GENETIC_LIB && EXPERIMENTAL + select SCHEDSTATS + help + This option will enable the genetic library on the zaphod + CPU scheduler. + # # compression support is select'ed if needed # Index: 2.6.12-genetic/include/linux/sched_zaphod.h =================================================================== --- 2.6.12-genetic.orig/include/linux/sched_zaphod.h 2005-08-15 16:16:26.000000000 -0500 +++ 2.6.12-genetic/include/linux/sched_zaphod.h 2005-08-15 16:18:21.000000000 -0500 @@ -71,4 +71,56 @@ extern void zaphod_reassess_at_renice(struct task_struct *p); extern void zaphod_reassess_at_new_cap(struct task_struct *p); +#ifdef CONFIG_GENETIC_ZAPHOD_CPU_SCHED +extern long sched_setaffinity(pid_t pid, cpumask_t new_mask); +extern long sched_getaffinity(pid_t pid, cpumask_t *mask); + + +#define ZAPHOD_SCHED_NUM_GENES 9 +#define ZAPHOD_SCHED_NUM_CHILDREN 8 +//#define ZAPHOD_SCHED_CHILD_LIFESPAN (9 * (HZ / 2)) +#define ZAPHOD_SCHED_CHILD_LIFESPAN (4 * HZ) +//#define ZAPHOD_SCHED_CHILD_LIFESPAN (6 * HZ) + +struct zaphod_rt_genes { + unsigned long sched_rr_time_slice; +}; +struct zaphod_intr_genes { + unsigned long ia_threshold; + unsigned long cpu_hog_threshold; +}; + +struct zaphod_fork_genes { + unsigned long initial_ia_bonus; +}; + +struct zaphod_general_genes { + unsigned long time_slice; + unsigned long max_ia_bonus; + unsigned long max_tpt_bonus; + unsigned long bgnd_time_slice_multiplier; + unsigned long zaphod_mode; +}; + +struct zaphod_stats_snapshot { + /* from struct runq_cpustats */ + unsigned long long total_delay; + unsigned long long total_rt_delay; + unsigned long long total_intr_delay; + unsigned long long total_rt_intr_delay; + unsigned long long total_fork_delay; + unsigned long long total_latency; + + /* from struct cpu_cpustats */ + unsigned long long nr_switches; + +#ifdef CONFIG_SCHEDSTATS + /* from sched_info */ + unsigned long cpu_time; + unsigned long run_delay; +#endif +}; + +#endif /* CONFIG_GENETIC_ZAPHOD_CPU_SCHED */ + #endif Index: 2.6.12-genetic/kernel/sched_spa.c =================================================================== --- 2.6.12-genetic.orig/kernel/sched_spa.c 2005-08-15 16:17:58.000000000 -0500 +++ 2.6.12-genetic/kernel/sched_spa.c 2005-08-16 09:05:45.000000000 -0500 @@ -69,26 +69,14 @@ p->sdu.spa.time_slice = t; } -/* - * These are the 'tuning knobs' of the scheduler: - * - * Default configurable timeslice is 100 msecs, maximum configurable - * timeslice is 1000 msecs and minumum configurable timeslice is 1 jiffy. - * Timeslices get renewed on task creation, on wake up and after they expire. - */ -#define MIN_TIMESLICE 1 -#define DEF_TIMESLICE ((100 * HZ / 1000) ? : MIN_TIMESLICE) -#define MAX_TIMESLICE ((1000 * HZ / 1000) ? : MIN_TIMESLICE) -#define DEF_DESKTOP_TIMESLICE ((60 * HZ / 1000) ? : MIN_TIMESLICE) - -static unsigned long time_slice = DEF_TIMESLICE; -static unsigned long sched_rr_time_slice = DEF_TIMESLICE; +unsigned long time_slice = DEF_TIMESLICE; +unsigned long sched_rr_time_slice = DEF_TIMESLICE; /* * Background tasks may have longer time slices as compensation */ #define task_is_bgnd(p) (unlikely((p)->sdu.spa.cpu_rate_cap == 0)) -static unsigned int bgnd_time_slice_multiplier = 1; +unsigned int bgnd_time_slice_multiplier = 1; #define TASK_PREEMPTS_CURR(p, rq) \ ((p)->prio < (rq)->curr->prio) Index: 2.6.12-genetic/include/config/cpusched/default/ingo.h =================================================================== --- 2.6.12-genetic.orig/include/config/cpusched/default/ingo.h 2005-08-15 10:54:42.000000000 -0500 +++ 2.6.12-genetic/include/config/cpusched/default/ingo.h 2005-08-16 09:28:37.000000000 -0500 @@ -1 +1 @@ -#define CONFIG_CPUSCHED_DEFAULT_INGO 1 +#undef CONFIG_CPUSCHED_DEFAULT_INGO Index: 2.6.12-genetic/include/config/cpusched/default/zaphod.h =================================================================== --- 2.6.12-genetic.orig/include/config/cpusched/default/zaphod.h 2005-08-15 10:54:42.000000000 -0500 +++ 2.6.12-genetic/include/config/cpusched/default/zaphod.h 2005-08-16 09:28:56.000000000 -0500 @@ -1 +1 @@ -#undef CONFIG_CPUSCHED_DEFAULT_ZAPHOD +#define CONFIG_CPUSCHED_DEFAULT_ZAPHOD 1