--- zzzz-none-000/linux-4.19.183/kernel/printk/printk.c 2021-03-24 10:07:39.000000000 +0000 +++ bcm63-7530ax-756/linux-4.19.183/kernel/printk/printk.c 2023-06-28 08:54:21.000000000 +0000 @@ -16,6 +16,11 @@ * 01Mar01 Andrew Morton */ +#ifdef CONFIG_AVM_FASTIRQ +#include +#define CLIENT_FIQ_PRIO FIQ_PRIO_WATCHDOG +#endif + #include #include #include @@ -58,6 +63,23 @@ #include "braille.h" #include "internal.h" +#if defined(CONFIG_AVM_FASTIRQ) + +#include +#define __NONLINUX_CONTEXT_NAME "FastIrq" +#define _BUILD_AVM_CONTEXT_FUNC(func) firq_##func +#else +#define _BUILD_AVM_CONTEXT_FUNC(func) func +#define is_avm_rte() 0 +#endif + + +#if defined(CONFIG_BCM_KF_PRINTK_INT_ENABLED) && defined(CONFIG_BCM_PRINTK_INT_ENABLED) +#ifdef CONFIG_RCU_STALL_COMMON +extern int rcu_cpu_stall_suppress; +#endif +#endif + int console_printk[4] = { CONSOLE_LOGLEVEL_DEFAULT, /* console_loglevel */ MESSAGE_LOGLEVEL_DEFAULT, /* default_message_loglevel */ @@ -364,6 +386,9 @@ u8 facility; /* syslog facility */ u8 flags:5; /* internal record flags */ u8 level:3; /* syslog level */ +#if defined(CONFIG_AVM_DEBUG) + u8 cpu; +#endif/*--- #if defined(CONFIG_AVM_DEBUG) ---*/ } #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS __packed __aligned(4) @@ -640,10 +665,17 @@ msg->facility = facility; msg->level = level & 7; msg->flags = flags & 0x1f; +#if defined(CONFIG_AVM_DEBUG) + if (!_BUILD_AVM_CONTEXT_FUNC(is_avm_rte)()) { + msg->cpu = raw_smp_processor_id(); + } else { + msg->cpu = raw_smp_processor_id() | 0x80; + } +#endif/*--- #if defined(CONFIG_AVM_DEBUG) ---*/ if (ts_nsec > 0) msg->ts_nsec = ts_nsec; else - msg->ts_nsec = local_clock(); + msg->ts_nsec = _BUILD_AVM_CONTEXT_FUNC(local_clock)(); memset(log_dict(msg) + dict_len, 0, pad_len); msg->len = size; @@ -1285,6 +1317,13 @@ } len += print_time(msg->ts_nsec, buf ? buf + len : NULL); + +#if defined(CONFIG_AVM_DEBUG) && defined(CONFIG_SMP) + if(buf) { + if(len && buf[len-1] == ' ') len--; + len += sprintf(&buf[len], "[%s%x] ", msg->cpu & 0x80 ? "F" : "", msg->cpu & ~0x80); + } +#endif /*--- #if defined(CONFIG_AVM_DEBUG) && defined(CONFIG_SMP) ---*/ return len; } @@ -1593,6 +1632,15 @@ return do_syslog(type, buf, len, SYSLOG_FROM_READER); } +#if defined(CONFIG_BCM_KF_PRINTK_INT_ENABLED) && defined(CONFIG_BCM_PRINTK_INT_ENABLED) + +static int console_trylock_spinning(void) +{ + return console_trylock(); +} + +#else + /* * Special console_lock variants that help to reduce the risk of soft-lockups. * They allow to pass console_lock to another printk() call using a busy wait. @@ -1732,6 +1780,7 @@ return 1; } +#endif /* * Call the console drivers, asking them to write out @@ -1753,9 +1802,11 @@ continue; if (!(con->flags & CON_ENABLED)) continue; + if (con->flags & CON_MUTED) + continue; if (!con->write) continue; - if (!cpu_online(smp_processor_id()) && + if (!cpu_online(raw_smp_processor_id()) && !(con->flags & CON_ANYTIME)) continue; if (con->flags & CON_EXTENDED) @@ -1821,7 +1872,7 @@ cont.facility = facility; cont.level = level; cont.owner = current; - cont.ts_nsec = local_clock(); + cont.ts_nsec = _BUILD_AVM_CONTEXT_FUNC(local_clock)(); cont.flags = flags; } @@ -1950,6 +2001,25 @@ /* If called from the scheduler, we can not call up(). */ if (!in_sched && pending_output) { +#if defined(CONFIG_BCM_KF_PRINTK_INT_ENABLED) && defined(CONFIG_BCM_PRINTK_INT_ENABLED) + int may_trylock = 1; + + /* + * we can't take a sleeping lock with IRQs or preeption disabled + * so we can't print in these contexts + */ + if(oops_in_progress || early_boot_irqs_disabled || + preempt_count() > 1 || irqs_disabled()) { +#ifdef CONFIG_RCU_STALL_COMMON + /* This variable is only set when we are in a kernel panic + * OR we are handling a magic sysrq. Allow prints in these + * scenarios + */ + if(!rcu_cpu_stall_suppress) +#endif + may_trylock = 0; + } +#endif /* * Disable preemption to avoid being preempted while holding * console_sem which would prevent anyone from printing to @@ -1961,7 +2031,11 @@ * semaphore. The release will print out buffers and wake up * /dev/kmsg and syslog() users. */ +#if defined(CONFIG_BCM_KF_PRINTK_INT_ENABLED) && defined(CONFIG_BCM_PRINTK_INT_ENABLED) + if (may_trylock && console_trylock_spinning()) +#else if (console_trylock_spinning()) +#endif console_unlock(); preempt_enable(); } @@ -2448,6 +2522,10 @@ console_seq++; raw_spin_unlock(&logbuf_lock); +#if defined(CONFIG_BCM_KF_PRINTK_INT_ENABLED) && defined(CONFIG_BCM_PRINTK_INT_ENABLED) + printk_safe_exit_irqrestore(flags); + call_console_drivers(ext_text, ext_len, text, len); +#else /* * While actively printing out messages, if another printk() * were to occur on another CPU, it may wait for this one to @@ -2466,6 +2544,7 @@ } printk_safe_exit_irqrestore(flags); +#endif if (do_cond_resched) cond_resched(); @@ -2591,6 +2670,34 @@ } EXPORT_SYMBOL(console_start); +void console_mute(struct console *console) +{ + console_lock(); + console_mute_nolock(console); + console_unlock(); +} +EXPORT_SYMBOL(console_mute); + +void console_mute_nolock(struct console *console) +{ + console->flags |= CON_MUTED; +} +EXPORT_SYMBOL(console_mute_nolock); + +void console_unmute(struct console *console) +{ + console_lock(); + console_unmute_nolock(console); + console_unlock(); +} +EXPORT_SYMBOL(console_unmute); + +void console_unmute_nolock(struct console *console) +{ + console->flags &= ~CON_MUTED; +} +EXPORT_SYMBOL(console_unmute_nolock); + static int __read_mostly keep_bootcon; static int __init keep_bootcon_setup(char *str) @@ -3024,6 +3131,16 @@ } EXPORT_SYMBOL(printk_timed_ratelimit); + +DEFINE_RATELIMIT_STATE(bcm_printk_ratelimit_state, 30 * HZ, 10); + +int __bcm_printk_ratelimit(const char *func) +{ + return ___ratelimit(&bcm_printk_ratelimit_state, func); +} +EXPORT_SYMBOL(__bcm_printk_ratelimit); + + static DEFINE_SPINLOCK(dump_list_lock); static LIST_HEAD(dump_list);