|
1 | 1 | #include <linux/sched/clock.h> |
2 | | -#include <linux/sched/cond_resched.h> |
3 | 2 | #include <linux/sched/cputime.h> |
| 3 | +#include <asm/tsc.h> |
4 | 4 | #include <linux/sched/isolation.h> |
5 | 5 | #include <linux/sched/nohz.h> |
6 | 6 | #include "sched.h" |
@@ -29,21 +29,30 @@ typedef struct { |
29 | 29 |
|
30 | 30 | easy_sched_struct_def easy_cpu_contexts[128] = {0}; |
31 | 31 |
|
32 | | -__inline void egg(void) |
| 32 | +static const char *unix_days[] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"}; |
| 33 | +static const char *prof_words[] = {"You can't just delete that!", "Your math is too poor!", "Without the formula, it's meaningless!", "Go back and study linear algebra!", "This is not rigorous.", "We need publish papers!", "Intuition won't work here!", "This is not scientific research!", "You are running blind code!"}; |
| 34 | +static __inline void egg(void) |
33 | 35 | { |
34 | 36 | static uint8_t shown = 0; |
35 | 37 | if (shown) return; |
36 | | - const char *unix_day[] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"}; |
37 | 38 | pr_alert("easy_sched: From Beijing to Hiroshima, Professors kept saying the same thing:\n"); |
38 | 39 | pr_alert("easy_sched: 'Your math is too poor!'\n"); |
39 | 40 | pr_alert("easy_sched: But every time they said it, I had already deleted their math-heavy bullshit,\n"); |
40 | 41 | pr_alert("easy_sched: and the system still ran — faster, cleaner, simpler.\n"); |
41 | 42 | if (__ktime_get_real_seconds()) |
42 | | - pr_alert("!!! Happy %s !!!\n", unix_day[(__ktime_get_real_seconds()/86400)%7]); |
| 43 | + pr_alert("!!! Happy %s !!!\n", unix_days[(__ktime_get_real_seconds()/86400)%7]); |
43 | 44 | else |
44 | 45 | pr_alert("!!! Happy ???Day, time unknown 233 !!!\n"); |
45 | 46 | shown = 1; |
46 | 47 | } |
| 48 | +static __inline void egg2(struct task_struct *p) |
| 49 | +{ |
| 50 | + static uint64_t last_yield = 0; |
| 51 | + uint64_t now_sec = __ktime_get_real_seconds(); |
| 52 | + if (now_sec-last_yield<30) return; |
| 53 | + pr_alert("\033[1;31mWarning from Professors with PID=%lld: %s\033[0m\n", p->pid, prof_words[get_cycles()%(sizeof(prof_words)/sizeof(char *))]); |
| 54 | + last_yield = now_sec; |
| 55 | +} |
47 | 56 |
|
48 | 57 | void easy_sched_init(easy_sched_struct_def *easy_context) |
49 | 58 | { |
@@ -81,7 +90,7 @@ static void dequeue_task_easy(struct rq *rq, struct task_struct *p, int flags) |
81 | 90 | pr_alert("!!! %s 0x%llx failed !!!\n", __func__, p); |
82 | 91 | } |
83 | 92 |
|
84 | | -static uint8_t hlt_sleep_eligible(struct task_struct *p) |
| 93 | +static __inline uint8_t hlt_sleep_eligible(struct task_struct *p) |
85 | 94 | { |
86 | 95 | if ((p->__state == TASK_HLT_SLEEP) && ((p->nivcsw & 0xFF) != 0xFF)) |
87 | 96 | { |
@@ -118,7 +127,7 @@ static void yield_task_easy(struct rq *rq) |
118 | 127 | easy_context->index++; |
119 | 128 | } |
120 | 129 |
|
121 | | -static void put_prev_task_easy(struct rq *rq, struct task_struct *p) { } |
| 130 | +static void put_prev_task_easy(struct rq *rq, struct task_struct *p) { egg2(p); } |
122 | 131 | static void set_next_task_easy(struct rq *rq, struct task_struct *p, bool first) { } |
123 | 132 | static void check_preempt_curr_easy(struct rq *rq, struct task_struct *p, int flags) { } |
124 | 133 | static void task_tick_easy(struct rq *rq, struct task_struct *p, int queued) { } |
|
0 commit comments