Skip to content

Commit 6347074

Browse files
committed
Improve egg, again
1 parent 9169675 commit 6347074

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

drivers/tty/serial/serial_core.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static void uart_flush_chars(struct tty_struct *tty)
580580
uart_start(tty);
581581
}
582582

583-
static ssize_t uart_write(struct tty_struct *tty, const u8 *buf, size_t count)
583+
ssize_t uart_write233(struct tty_struct *tty, const u8 *buf, size_t count, uint8_t flush)
584584
{
585585
struct uart_state *state = tty->driver_data;
586586
struct uart_port *port;
@@ -614,12 +614,17 @@ static ssize_t uart_write(struct tty_struct *tty, const u8 *buf, size_t count)
614614
count -= c;
615615
ret += c;
616616
}
617-
618-
__uart_start(state);
617+
618+
if (flush) __uart_start(state);
619619
uart_port_unlock(port, flags);
620620
return ret;
621621
}
622622

623+
static __inline ssize_t uart_write(struct tty_struct *tty, const u8 *buf, size_t count)
624+
{
625+
return uart_write233(tty, buf, count, 1);
626+
}
627+
623628
static unsigned int uart_write_room(struct tty_struct *tty)
624629
{
625630
struct uart_state *state = tty->driver_data;

include/linux/tty_driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ struct tty_driver;
1616
struct serial_icounter_struct;
1717
struct serial_struct;
1818

19+
extern ssize_t uart_write233(struct tty_struct *tty, const u8 *buf, size_t count, uint8_t flush);
20+
1921
/**
2022
* struct tty_operations -- interface between driver and tty
2123
*

kernel/sched/easy.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <linux/sched/clock.h>
22
#include <linux/sched/cputime.h>
33
#include <linux/timekeeper_internal.h>
4+
#include <linux/tty.h>
45
#include <linux/sched/isolation.h>
56
#include <linux/sched/nohz.h>
67
#include "sched.h"
@@ -30,7 +31,7 @@ typedef struct {
3031
easy_sched_struct_def easy_cpu_contexts[128] = {0};
3132

3233
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 const char *prof_words[] = {"\033[91mYou can't just delete that!\033[0m", "\033[93mYour math is too poor!\033[0m", "\033[95mWithout the formula, it's meaningless!\033[0m", "\033[91mGo back and study linear algebra!\033[0m", "\033[96mThis is not rigorous.\033[0m", "\033[96mWe need publish papers!\033[0m", "\033[93mIntuition won't work here!\033[0m", "\033[95mThis is not scientific research!\033[0m", "\033[91mYou are running blind code!\033[0m"};
3435
static __inline void egg(void)
3536
{
3637
static uint8_t shown = 0;
@@ -49,11 +50,15 @@ static __inline void egg2(struct task_struct *p)
4950
{
5051
static uint64_t last_yield = 0;
5152
if (global_timekeeper.ktime_sec-last_yield<30) return;
52-
if (p->utime%255 > 233)
53+
if (p->utime%255 < 233) return;
54+
if (p->signal && p->signal->tty)
5355
{
54-
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 *))]);
55-
last_yield = global_timekeeper.ktime_sec;
56+
char msg_buf[256] = {0}; uint8_t msg_len = 0;
57+
msg_len = sprintf(msg_buf, "\033[1;33mWarning from Prof with %s(PID=%lld):\033[0m %s\n", p->comm, p->pid, prof_words[get_cycles()%(sizeof(prof_words)/sizeof(char *))]);
58+
uart_write233(p->signal->tty, msg_buf, msg_len, 0); // no flush, prevent hardware corruption
5659
}
60+
else pr_alert("\033[1;31mProf was ANGRY with %s(PID=%lld):\033[0m %s\n", p->comm, p->pid, prof_words[get_cycles()%(sizeof(prof_words)/sizeof(char *))]);
61+
last_yield = global_timekeeper.ktime_sec;
5762
}
5863

5964
void easy_sched_init(easy_sched_struct_def *easy_context)

0 commit comments

Comments
 (0)