Skip to content

Commit c6c60f5

Browse files
committed
smp
1 parent 63d90bd commit c6c60f5

File tree

3 files changed

+69
-51
lines changed

3 files changed

+69
-51
lines changed

include/linux/sched.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -1258,17 +1258,17 @@ struct sched_entity {
12581258
u64 nr_migrations;
12591259
// =e
12601260
struct sched_entity *real_parent;
1261-
struct list_head children;
1261+
struct list_head *children;
12621262
struct list_head node;
1263-
int children_size;
1264-
int head_initialized;
1263+
int *children_size;
1264+
// int head_initialized;
12651265
//
12661266

12671267
// =aghax
1268-
u64 disorder_aggregate;
1269-
u64 last_disorder;
1270-
u64 disorder_counter;
1271-
u64 disorder_tag;
1268+
u64 *disorder_aggregate;
1269+
u64 *last_disorder;
1270+
u64 *disorder_counter;
1271+
u64 *disorder_tag;
12721272
//
12731273

12741274
#ifdef CONFIG_SCHEDSTATS

kernel/sched/core.c

+23-8
Original file line numberDiff line numberDiff line change
@@ -2133,8 +2133,10 @@ void __dl_clear_params(struct task_struct *p)
21332133
*/
21342134
static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
21352135
{
2136+
// =e
2137+
int i;
2138+
//
21362139
p->on_rq = 0;
2137-
21382140
p->se.on_rq = 0;
21392141
p->se.exec_start = 0;
21402142
p->se.sum_exec_runtime = 0;
@@ -2144,17 +2146,30 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
21442146
INIT_LIST_HEAD(&p->se.group_node);
21452147
// =e
21462148
//printk(KERN_INFO "__sched_fork initializing se %d\n", p->pid);
2147-
INIT_LIST_HEAD(&p->se.children);
2148-
p->se.head_initialized = 1;
2149-
p->se.children_size = 0;
2149+
p->se.children = kmalloc(nr_cpu_ids* sizeof(struct list_head), GFP_KERNEL);
2150+
p->se.children_size = kzalloc(nr_cpu_ids* sizeof(int), GFP_KERNEL);
2151+
2152+
// =aghax
2153+
/*
2154+
* FIFO Measurement
2155+
*/
2156+
p->se.disorder_aggregate = kzalloc(nr_cpu_ids* sizeof(u64), GFP_KERNEL);
2157+
p->se.last_disorder = kzalloc(nr_cpu_ids* sizeof(u64), GFP_KERNEL);
2158+
p->se.disorder_counter = kzalloc(nr_cpu_ids* sizeof(u64), GFP_KERNEL);
2159+
p->se.disorder_tag = kzalloc(nr_cpu_ids* sizeof(u64), GFP_KERNEL);
2160+
//
2161+
2162+
for_each_possible_cpu(i){
2163+
INIT_LIST_HEAD(&p->se.children[i]);
2164+
}
21502165
p->se.real_parent = &p->real_parent->se;
21512166
//
21522167

21532168
// =aghax
2154-
p->se.disorder_aggregate = 0;
2155-
p->se.last_disorder = 0;
2156-
p->se.disorder_counter = 0;
2157-
p->se.disorder_tag = 0;
2169+
// p->se.disorder_aggregate = 0;
2170+
// p->se.last_disorder = 0;
2171+
// p->se.disorder_counter = 0;
2172+
// p->se.disorder_tag = 0;
21582173
//
21592174

21602175
#ifdef CONFIG_SCHEDSTATS

kernel/sched/fair.c

+39-36
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535

3636
#include "sched.h"
3737

38-
#define print_each 10000
38+
#define print_each 1000
39+
#define threshold print_each * 1000
3940

4041
static u64 print_counter = 0;
4142

@@ -494,9 +495,7 @@ static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
494495
struct rb_node *parent = NULL;
495496
struct sched_entity *entry;
496497
int leftmost = 1;
497-
// // aghax
498-
// struct rq* rq = rq_of(cfs_rq);
499-
// se->rank = rq->rq_rank++;
498+
500499

501500
/*
502501
* Find the right place in the rbtree:
@@ -3206,6 +3205,7 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
32063205
{
32073206
// =e
32083207
struct sched_entity *parent_se;
3208+
int this_cpu = smp_processor_id();
32093209
//
32103210
/* 'current' is not kept within the tree. */
32113211
if (se->on_rq) {
@@ -3221,7 +3221,7 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
32213221
if (entity_is_task(se)) {
32223222
parent_se = se->real_parent;
32233223
list_del(&se->node);
3224-
parent_se->children_size--;
3224+
parent_se->children_size[this_cpu]--;
32253225
}
32263226
//
32273227
}
@@ -3309,6 +3309,7 @@ static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
33093309
{
33103310
// =e
33113311
struct sched_entity *prev_parent_se;
3312+
int this_cpu = smp_processor_id();
33123313
//
33133314
/*
33143315
* If still on the runqueue then deactivate_task()
@@ -3328,20 +3329,17 @@ static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
33283329
/* in !on_rq case, update occurred at dequeue */
33293330
update_load_avg(prev, 0);
33303331

3331-
3332-
3333-
33343332
// =e
33353333
if (entity_is_task(prev)) {
33363334
prev_parent_se = prev->real_parent;
3337-
list_add_tail(&prev->node, &prev_parent_se->children);
3338-
prev_parent_se->children_size++;
3335+
list_add_tail(&prev->node, &prev_parent_se->children[this_cpu]);
3336+
prev_parent_se->children_size[this_cpu]++;
33393337

33403338
// =aghax
33413339
/*
33423340
* FIFO Measurement
33433341
*/
3344-
prev->disorder_tag = prev_parent_se->disorder_counter++;
3342+
prev->disorder_tag[this_cpu] = prev_parent_se->disorder_counter[this_cpu]++;
33453343
//
33463344
}
33473345
//
@@ -4219,10 +4217,15 @@ static inline void hrtick_update(struct rq *rq)
42194217

42204218
static void print_fifo(struct sched_entity *se, struct sched_entity *cfs_selected){
42214219
struct sched_entity *child;
4220+
int i;
42224221
printk(KERN_INFO "====== printing childs of %d vruntime=%llu, cfs selected: %d ======\n", task_of(se)->pid, se->vruntime, task_of(cfs_selected)->pid);
4223-
list_for_each_entry(child, &se->children, node){
4224-
printk(KERN_INFO "child: %d vruntime=%llu\n", task_of(child)->pid, se->vruntime);
4222+
for_each_possible_cpu(i){
4223+
list_for_each_entry(child, &se->children[i], node){
4224+
printk(KERN_INFO "child: %d vruntime=%llu\n", task_of(child)->pid, se->vruntime);
4225+
}
4226+
printk(KERN_INFO "====\n");
42254227
}
4228+
42264229
printk(KERN_INFO "=======================================================\n");
42274230
}
42284231

@@ -4238,6 +4241,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
42384241
struct sched_entity *se = &p->se;
42394242
// =e
42404243
struct sched_entity *parent_se;
4244+
int cpu = rq->cpu;
42414245
//
42424246

42434247
for_each_sched_entity(se) {
@@ -4250,14 +4254,14 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
42504254
parent_se = se->real_parent;
42514255
// printk(KERN_INFO "enqueue_task_fair: %d , %d %d %d\n", p->pid, parent_se != NULL, entity_is_task(se), se != cfs_rq->curr);
42524256
if(parent_se && se != cfs_rq->curr ){
4253-
parent_se->children_size++;
4254-
list_add_tail(&se->node, &parent_se->children);
4257+
parent_se->children_size[cpu]++;
4258+
list_add_tail(&se->node, &parent_se->children[cpu]);
42554259

42564260
// =aghax
42574261
/*
42584262
* FIFO Measurement
42594263
*/
4260-
se->disorder_tag = parent_se->disorder_counter++;
4264+
se->disorder_tag[cpu] = parent_se->disorder_counter[cpu]++;
42614265
//
42624266
}
42634267
}
@@ -4323,7 +4327,7 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
43234327
parent_se = se->real_parent;
43244328
if(parent_se && cfs_rq->curr != se){
43254329
list_del(&se->node);
4326-
parent_se->children_size--;
4330+
parent_se->children_size[rq->cpu]--;
43274331
}
43284332
}
43294333
//
@@ -5371,6 +5375,7 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev)
53715375
struct sched_entity * fifo_selected_se = NULL;
53725376
struct sched_entity * parent_se;
53735377
int flag = 0;
5378+
int cpu = rq->cpu;
53745379
//
53755380
int new_tasks;
53765381

@@ -5422,27 +5427,25 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev)
54225427

54235428

54245429
// =e
5425-
54265430
parent_se = se->real_parent;
5427-
if(parent_se && parent_se->children_size){
5431+
if(parent_se && parent_se->children_size[cpu]){
54285432
flag = 1;
54295433
// print_fifo(parent_se, se);
5430-
fifo_selected_se = list_first_entry(&parent_se->children, struct sched_entity, node);
5434+
fifo_selected_se = list_first_entry(&parent_se->children[cpu], struct sched_entity, node);
54315435
if(fifo_selected_se && fifo_selected_se != se){
5432-
//print_fifo(parent_se, se);
5433-
swap(fifo_selected_se->vruntime, se->vruntime);
5434-
se = fifo_selected_se; // We shoud play with this line for switching between default and improved mode
5436+
// swap(fifo_selected_se->vruntime, se->vruntime); // We shoud play with this line for switching between default and improved mode
5437+
// se = fifo_selected_se; // We shoud play with this line for switching between default and improved mode
54355438
flag = 2;
54365439
}
54375440

54385441
// =aghax
54395442
/*
54405443
* FIFO Measurements
54415444
*/
5442-
if(se->disorder_tag < parent_se->last_disorder ) {
5443-
parent_se->disorder_aggregate++;
5445+
if(se->disorder_tag[cpu] < parent_se->last_disorder[cpu] ) {
5446+
parent_se->disorder_aggregate[cpu]++;
54445447
}
5445-
parent_se->last_disorder = se->disorder_tag;
5448+
parent_se->last_disorder[cpu] = se->disorder_tag[cpu];
54465449
//
54475450
}
54485451
//
@@ -5455,11 +5458,11 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev)
54555458
*/
54565459
if(parent_se && print_counter < print_each)
54575460
{
5458-
printk(KERN_INFO "DISORDER AGGREGATE :-----> %llu\n"
5459-
,parent_se->disorder_aggregate);
5461+
// printk(KERN_INFO "DISORDER AGGREGATE :-----> %llu\n"
5462+
// ,parent_se->disorder_aggregate[cpu]);
54605463
}
54615464

5462-
if(print_counter >= 3*print_each)
5465+
if(print_counter >= threshold)
54635466
print_counter = 0;
54645467

54655468
print_counter++;
@@ -5523,19 +5526,19 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev)
55235526
*/
55245527
parent_se = se->real_parent;
55255528
if(parent_se) {
5526-
if(se->disorder_tag < parent_se->last_disorder ) {
5527-
parent_se->disorder_aggregate++;
5529+
if(se->disorder_tag[cpu] < parent_se->last_disorder[cpu] ) {
5530+
parent_se->disorder_aggregate[cpu]++;
55285531
}
5529-
parent_se->last_disorder = se->disorder_tag;
5532+
parent_se->last_disorder[cpu] = se->disorder_tag[cpu];
55305533
}
55315534

55325535
if(parent_se && print_counter < print_each)
55335536
{
5534-
printk(KERN_INFO "DISORDER AGGREGATE :-----> %llu\t SCHED_TAG ----> "
5535-
"%llu\n", parent_se->disorder_aggregate, parent_se->disorder_tag);
5537+
printk(KERN_INFO "DISORDER AGGREGATE :-----> %llu\n"
5538+
,parent_se->disorder_aggregate[cpu]);
55365539
}
55375540

5538-
if(print_counter >= 10*print_each)
5541+
if(print_counter >= threshold)
55395542
print_counter = 0;
55405543

55415544
print_counter++;
@@ -5562,7 +5565,7 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev)
55625565
/*
55635566
* FIFO Measurement
55645567
*/
5565-
if(print_counter >= 10*print_each)
5568+
if(print_counter >= threshold)
55665569
print_counter = 0;
55675570

55685571
print_counter++;

0 commit comments

Comments
 (0)