Skip to content

Commit 2279d9f

Browse files
committed
Improve egg
1 parent 13d76bd commit 2279d9f

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

arch/x86/mm/fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ void do_user_addr_fault(struct pt_regs *regs,
14111411
retry:
14121412
vma = lock_mm_and_find_vma(mm, address, regs);
14131413
if (unlikely(!vma)) {
1414-
pr_alert("%s %s %d, lock_mm_and_find_vma failed !!!\n", __FILE__, __func__, __LINE__);
1414+
//pr_alert("%s %s %d, lock_mm_and_find_vma failed !!!\n", __FILE__, __func__, __LINE__);
14151415
bad_area_nosemaphore(regs, error_code, address);
14161416
return;
14171417
}

kernel/sched/easy.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <linux/sched/clock.h>
2-
#include <linux/sched/cond_resched.h>
32
#include <linux/sched/cputime.h>
3+
#include <asm/tsc.h>
44
#include <linux/sched/isolation.h>
55
#include <linux/sched/nohz.h>
66
#include "sched.h"
@@ -29,21 +29,30 @@ typedef struct {
2929

3030
easy_sched_struct_def easy_cpu_contexts[128] = {0};
3131

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)
3335
{
3436
static uint8_t shown = 0;
3537
if (shown) return;
36-
const char *unix_day[] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};
3738
pr_alert("easy_sched: From Beijing to Hiroshima, Professors kept saying the same thing:\n");
3839
pr_alert("easy_sched: 'Your math is too poor!'\n");
3940
pr_alert("easy_sched: But every time they said it, I had already deleted their math-heavy bullshit,\n");
4041
pr_alert("easy_sched: and the system still ran — faster, cleaner, simpler.\n");
4142
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]);
4344
else
4445
pr_alert("!!! Happy ???Day, time unknown 233 !!!\n");
4546
shown = 1;
4647
}
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+
}
4756

4857
void easy_sched_init(easy_sched_struct_def *easy_context)
4958
{
@@ -81,7 +90,7 @@ static void dequeue_task_easy(struct rq *rq, struct task_struct *p, int flags)
8190
pr_alert("!!! %s 0x%llx failed !!!\n", __func__, p);
8291
}
8392

84-
static uint8_t hlt_sleep_eligible(struct task_struct *p)
93+
static __inline uint8_t hlt_sleep_eligible(struct task_struct *p)
8594
{
8695
if ((p->__state == TASK_HLT_SLEEP) && ((p->nivcsw & 0xFF) != 0xFF))
8796
{
@@ -118,7 +127,7 @@ static void yield_task_easy(struct rq *rq)
118127
easy_context->index++;
119128
}
120129

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); }
122131
static void set_next_task_easy(struct rq *rq, struct task_struct *p, bool first) { }
123132
static void check_preempt_curr_easy(struct rq *rq, struct task_struct *p, int flags) { }
124133
static void task_tick_easy(struct rq *rq, struct task_struct *p, int queued) { }

0 commit comments

Comments
 (0)