Linux 6.3 + nintendo controller fixes

This commit is contained in:
ferrreo 2023-04-10 18:42:41 +01:00
parent 7926eb92df
commit f464089613
8 changed files with 6932 additions and 29905 deletions

6
config
View File

@ -2,7 +2,7 @@
# Automatically generated file; DO NOT EDIT.
# Linux/x86 6.2.1 Kernel Configuration
#
CONFIG_CC_VERSION_TEXT="gcc (GCC) 12.2.1 20230216"
CONFIG_CC_VERSION_TEXT="gcc (GCC) 12.2.1 20230311"
CONFIG_CC_IS_GCC=y
CONFIG_GCC_VERSION=120201
CONFIG_CLANG_VERSION=0
@ -534,7 +534,7 @@ CONFIG_X86_PAT=y
CONFIG_ARCH_USES_PG_UNCACHED=y
CONFIG_X86_UMIP=y
CONFIG_CC_HAS_IBT=y
# CONFIG_X86_KERNEL_IBT is not set
CONFIG_X86_KERNEL_IBT=y
CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS=y
# CONFIG_X86_INTEL_TSX_MODE_OFF is not set
# CONFIG_X86_INTEL_TSX_MODE_ON is not set
@ -6938,7 +6938,7 @@ CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y
# CONFIG_LOGO is not set
# end of Graphics support
# CONFIG_DRM_ACCEL is not set
CONFIG_DRM_ACCEL=y
CONFIG_SOUND=m
CONFIG_SOUND_OSS_CORE=y
# CONFIG_SOUND_OSS_CORE_PRECLAIM is not set

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,38 +1,40 @@
From e016cce088886f56617becc8fcc598a0114e4faa Mon Sep 17 00:00:00 2001
From d1d05832308e210422f7c52d052b026deb9fabf1 Mon Sep 17 00:00:00 2001
From: Peter Jung <admin@ptr1337.dev>
Date: Sat, 11 Mar 2023 18:44:19 +0100
Subject: [PATCH] bore-eevdf
Date: Thu, 6 Apr 2023 19:12:01 +0200
Subject: [PATCH] bore
Signed-off-by: Peter Jung <admin@ptr1337.dev>
---
include/linux/sched.h | 5 ++
init/Kconfig | 20 +++++++
kernel/sched/core.c | 29 ++++++++++
kernel/sched/debug.c | 3 +
kernel/sched/fair.c | 124 +++++++++++++++++++++++++++++++++++++++++-
5 files changed, 180 insertions(+), 1 deletion(-)
include/linux/sched.h | 6 ++
init/Kconfig | 20 ++++++
kernel/sched/core.c | 30 ++++++++
kernel/sched/debug.c | 3 +
kernel/sched/fair.c | 149 +++++++++++++++++++++++++++++++++++++++-
kernel/sched/features.h | 8 +++
6 files changed, 213 insertions(+), 3 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 764df627c243..f912da35db34 100644
index 63d242164b1a..39a046d6cf90 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -558,6 +558,11 @@ struct sched_entity {
@@ -555,6 +555,12 @@ struct sched_entity {
u64 sum_exec_runtime;
u64 vruntime;
u64 prev_sum_exec_runtime;
+#ifdef CONFIG_SCHED_BORE
+ u64 prev_burst_time;
+ u64 burst_time;
+ u8 burst_score;
+ u64 max_burst_time;
+ u8 penalty_score;
+#endif // CONFIG_SCHED_BORE
s64 lag;
u64 slice;
u64 nr_migrations;
diff --git a/init/Kconfig b/init/Kconfig
index 748a9491ca12..d10f1e6257cd 100644
index 1fb5f313d18f..6595e5ed2416 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1318,6 +1318,26 @@ config CHECKPOINT_RESTORE
@@ -1285,6 +1285,26 @@ config CHECKPOINT_RESTORE
If unsure, say N here.
@ -60,89 +62,90 @@ index 748a9491ca12..d10f1e6257cd 100644
bool "Automatic process group scheduling"
select CGROUPS
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 9db5f9ec9022..1f1e1f586407 100644
index 0d18c3969f90..34db768f6ba8 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4418,6 +4418,21 @@ int wake_up_state(struct task_struct *p, unsigned int state)
@@ -4418,6 +4418,22 @@ int wake_up_state(struct task_struct *p, unsigned int state)
return try_to_wake_up(p, state, 0);
}
+#ifdef CONFIG_SCHED_BORE
+static inline void sched_fork_update_prev_burst(struct task_struct *p)
+static inline void adjust_prev_burst(struct task_struct *p)
+{
+ struct task_struct *sib;
+ u32 cnt = 0;
+ u64 sum = 0, avg = 0;
+ struct task_struct *sib;
+ list_for_each_entry(sib, &p->sibling, sibling) {
+ cnt++;
+ sum += sib->se.prev_burst_time >> 8;
+ sum += sib->se.max_burst_time >> 8;
+ }
+ if (cnt) avg = div_u64(sum, cnt) << 8;
+ if (p->se.prev_burst_time < avg) p->se.prev_burst_time = avg;
+ p->se.max_burst_time = p->se.prev_burst_time;
+}
+#endif // CONFIG_SCHED_BORE
+
/*
* Perform scheduler related setup for a newly forked process p.
* p is forked by current.
@@ -4434,6 +4449,9 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
@@ -4434,6 +4450,9 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
p->se.prev_sum_exec_runtime = 0;
p->se.nr_migrations = 0;
p->se.vruntime = 0;
+#ifdef CONFIG_SCHED_BORE
+ p->se.burst_time = 0;
+#endif // CONFIG_SCHED_BORE
p->se.dur_avg = 0;
p->se.prev_sleep_sum_runtime = 0;
p->se.lag = 0;
@@ -4664,6 +4682,10 @@ late_initcall(sched_core_sysctl_init);
INIT_LIST_HEAD(&p->se.group_node);
#ifdef CONFIG_FAIR_GROUP_SCHED
@@ -4659,6 +4678,9 @@ late_initcall(sched_core_sysctl_init);
int sched_fork(unsigned long clone_flags, struct task_struct *p)
{
__sched_fork(clone_flags, p);
+#ifdef CONFIG_SCHED_BORE
+ sched_fork_update_prev_burst(p);
+ p->se.burst_time = 0;
+ adjust_prev_burst(p);
+#endif // CONFIG_SCHED_BORE
/*
* We mark the process as NEW here. This guarantees that
* nobody will actually run it, and a signal or other external
@@ -9153,6 +9175,9 @@ void __init init_idle(struct task_struct *idle, int cpu)
@@ -9126,6 +9148,10 @@ void __init init_idle(struct task_struct *idle, int cpu)
idle->__state = TASK_RUNNING;
idle->se.exec_start = sched_clock();
+#ifdef CONFIG_SCHED_BORE
+ idle->se.prev_burst_time = 0;
+ idle->se.max_burst_time = 0;
+#endif //CONFIG_SCHED_BORE
/*
* PF_KTHREAD should already be set at this point; regardless, make it
* look like a proper per-CPU kthread.
@@ -9820,6 +9845,10 @@ void __init sched_init(void)
@@ -9793,6 +9819,10 @@ void __init sched_init(void)
BUG_ON(&dl_sched_class != &stop_sched_class + 1);
#endif
+#ifdef CONFIG_SCHED_BORE
+ printk(KERN_INFO "BORE (Burst-Oriented Response Enhancer) CPU Scheduler modification for 1.7-eevdf2 by Masahito Suzuki");
+ printk(KERN_INFO "BORE (Burst-Oriented Response Enhancer) CPU Scheduler modification 2.1.1 by Masahito Suzuki");
+#endif // CONFIG_SCHED_BORE
+
wait_bit_init();
#ifdef CONFIG_FAIR_GROUP_SCHED
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index fe9edfa43f65..3672df7c1f6a 100644
index 1637b65ba07a..752c43a9ff13 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -551,6 +551,9 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
@@ -547,6 +547,9 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
SPLIT_NS(schedstat_val_or_zero(p->stats.sum_sleep_runtime)),
SPLIT_NS(schedstat_val_or_zero(p->stats.sum_block_runtime)));
+#ifdef CONFIG_SCHED_BORE
+ SEQ_printf(m, " %2d", p->se.burst_score);
+ SEQ_printf(m, " %2d", p->se.penalty_score);
+#endif
#ifdef CONFIG_NUMA_BALANCING
SEQ_printf(m, " %d %d", task_node(p), task_numa_group_id(p));
#endif
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index c40b775452bc..1e4ca5419a11 100644
index 6986ea31c984..ee461e4586ca 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -19,6 +19,9 @@
@ -151,19 +154,19 @@ index c40b775452bc..1e4ca5419a11 100644
* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
+ *
+ * Burst-Oriented Response Enhancer (BORE) CPU Scheduler
+ * Copyright (C) 2021 Masahito Suzuki <firelzrd@gmail.com>
+ * Copyright (C) 2021-2023 Masahito Suzuki <firelzrd@gmail.com>
*/
#include <linux/energy_model.h>
#include <linux/mmap_lock.h>
@@ -141,6 +144,16 @@ static unsigned int normalized_sysctl_sched_wakeup_granularity = 1000000UL;
@@ -126,6 +129,16 @@ static unsigned int normalized_sysctl_sched_wakeup_granularity = 1000000UL;
const_debug unsigned int sysctl_sched_migration_cost = 500000UL;
+#ifdef CONFIG_SCHED_BORE
+unsigned int __read_mostly sched_bore = 1;
+unsigned int __read_mostly sched_burst_penalty_scale = 1280;
+unsigned int __read_mostly sched_burst_granularity = 6;
+unsigned int __read_mostly sched_burst_smoothness = 2;
+unsigned int __read_mostly sched_bore = 3;
+unsigned int __read_mostly sched_burst_penalty_offset = 12;
+unsigned int __read_mostly sched_burst_penalty_scale = 1292;
+unsigned int __read_mostly sched_burst_smoothness = 1;
+static int three = 3;
+static int sixty_four = 64;
+static int maxval_12_bits = 4095;
@ -172,7 +175,7 @@ index c40b775452bc..1e4ca5419a11 100644
int sched_thermal_decay_shift;
static int __init setup_sched_thermal_decay_shift(char *str)
{
@@ -204,6 +217,44 @@ static unsigned int sysctl_numa_balancing_promote_rate_limit = 65536;
@@ -185,6 +198,44 @@ static unsigned int sysctl_numa_balancing_promote_rate_limit = 65536;
#ifdef CONFIG_SYSCTL
static struct ctl_table sched_fair_sysctls[] = {
@ -184,7 +187,16 @@ index c40b775452bc..1e4ca5419a11 100644
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = SYSCTL_ONE,
+ .extra2 = &three,
+ },
+ {
+ .procname = "sched_burst_penalty_offset",
+ .data = &sched_burst_penalty_offset,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = &sixty_four,
+ },
+ {
+ .procname = "sched_burst_penalty_scale",
@ -196,15 +208,6 @@ index c40b775452bc..1e4ca5419a11 100644
+ .extra2 = &maxval_12_bits,
+ },
+ {
+ .procname = "sched_burst_granularity",
+ .data = &sched_burst_granularity,
+ .maxlen = sizeof(unsigned int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .extra1 = SYSCTL_ZERO,
+ .extra2 = &sixty_four,
+ },
+ {
+ .procname = "sched_burst_smoothness",
+ .data = &sched_burst_smoothness,
+ .maxlen = sizeof(unsigned int),
@ -217,61 +220,70 @@ index c40b775452bc..1e4ca5419a11 100644
{
.procname = "sched_child_runs_first",
.data = &sysctl_sched_child_runs_first,
@@ -1182,6 +1233,39 @@ static void update_tg_load_avg(struct cfs_rq *cfs_rq)
@@ -891,6 +942,47 @@ static void update_tg_load_avg(struct cfs_rq *cfs_rq)
}
#endif /* CONFIG_SMP */
+#ifdef CONFIG_SCHED_BORE
+static inline void update_burst_score(struct sched_entity *se) {
+ u64 burst_time;
+ s32 bits;
+ u32 intgr, fdigs, dec10;
+
+ burst_time = max(se->burst_time, se->prev_burst_time);
+ bits = fls64(burst_time);
+ intgr = max((u32)bits, sched_burst_granularity) - sched_burst_granularity;
+ fdigs = max(bits - 1, (s32)sched_burst_granularity);
+ dec10 = (intgr << 10) | (burst_time << (64 - fdigs) >> 54);
+ se->burst_score = min((u32)39, dec10 * sched_burst_penalty_scale >> 20);
+static inline u32 __calc_bits10(u64 burst_time) {
+ u32 bits = fls64(burst_time);
+ u32 fdigs = likely(bits) ? bits - 1 : 0;
+ return (bits << 10) | (burst_time << (64 - fdigs) >> 54);
+}
+
+static u64 burst_scale(u64 delta, struct sched_entity *se) {
+ return mul_u64_u32_shr(delta, sched_prio_to_wmult[se->burst_score], 22);
+static inline u32 __calc_burst_score(u32 bits10, u32 offset) {
+ u32 val10 = max((s32)0, (s32)bits10 - (s32)(offset << 10));
+ return min((u32)39, val10 * sched_burst_penalty_scale >> 20);
+}
+
+static u64 calc_delta_fair_bscale(u64 delta, struct sched_entity *se) {
+ return burst_scale(calc_delta_fair(delta, se), se);
+static void update_burst_score(struct sched_entity *se) {
+ u32 bits10 = __calc_bits10(se->max_burst_time);
+ se->penalty_score = __calc_burst_score(bits10, sched_burst_penalty_offset);
+}
+
+static inline u64 penalty_scale(u64 delta, struct sched_entity *se) {
+ return mul_u64_u32_shr(delta, sched_prio_to_wmult[se->penalty_score], 22);
+}
+
+static inline u64 preempt_scale(
+ u64 delta, struct sched_entity *curr, struct sched_entity *se) {
+
+ u32 score = max(0, (s32)se->penalty_score - (s32)curr->penalty_score) >> 1;
+ return mul_u64_u32_shr(delta, sched_prio_to_wmult[min(39, 20 + score)], 22);
+}
+
+static inline u64 binary_smooth(u64 old, u64 new, unsigned int smoothness) {
+ return (new + old * ((1 << smoothness) - 1)) >> smoothness;
+}
+
+static inline void reset_burst(struct sched_entity *se) {
+static void reset_burst(struct sched_entity *se) {
+ se->prev_burst_time = binary_smooth(
+ se->prev_burst_time, se->burst_time, sched_burst_smoothness);
+ se->burst_time = 0;
+
+ se->max_burst_time = se->prev_burst_time;
+}
+#endif // CONFIG_SCHED_BORE
+
/*
* Update the current task's runtime statistics.
*/
@@ -1211,6 +1295,13 @@ static void update_curr(struct cfs_rq *cfs_rq)
@@ -920,6 +1012,14 @@ static void update_curr(struct cfs_rq *cfs_rq)
curr->sum_exec_runtime += delta_exec;
schedstat_add(cfs_rq->exec_clock, delta_exec);
+#ifdef CONFIG_SCHED_BORE
+ curr->burst_time += delta_exec;
+ curr->max_burst_time = max(curr->max_burst_time, curr->burst_time);
+ update_burst_score(curr);
+ if (sched_bore)
+ curr->vruntime += calc_delta_fair_bscale(delta_exec, curr);
+ if (sched_bore & 1)
+ curr->vruntime += penalty_scale(calc_delta_fair(delta_exec, curr), curr);
+ else
+#endif // CONFIG_SCHED_BORE
curr->vruntime += calc_delta_fair(delta_exec, curr);
/*
* XXX: strictly: vd_i += N*r_i/w_i such that: vd_i > ve_i
@@ -5283,6 +5374,11 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
update_min_vruntime(cfs_rq);
@@ -5013,8 +5113,14 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
se->prev_sum_exec_runtime = se->sum_exec_runtime;
}
@ -279,18 +291,30 @@ index c40b775452bc..1e4ca5419a11 100644
+static int
+wakeup_preempt_entity_bscale(struct sched_entity *curr,
+ struct sched_entity *se, bool do_scale);
+#endif // CONFIG_SCHED_BORE
+#else // CONFIG_SCHED_BORE
static int
wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se);
+#endif // CONFIG_SCHED_BORE
@@ -5330,7 +5426,13 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr)
/*
* Pick the next process, keeping these things in mind, in this order:
@@ -5053,16 +5159,34 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr)
second = curr;
}
+#ifdef CONFIG_SCHED_BORE
+ if (second && wakeup_preempt_entity_bscale(
+ second, left, sched_bore & 2) < 1)
+#else // CONFIG_SCHED_BORE
if (second && wakeup_preempt_entity(second, left) < 1)
+#endif // CONFIG_SCHED_BORE
se = second;
}
- if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) {
+#ifdef CONFIG_SCHED_BORE
+ if (cfs_rq->next && wakeup_preempt_entity_bscale(
+ cfs_rq->next, left, sched_bore & 2) < 1)
+ cfs_rq->next, left, sched_bore & 2) < 1)
+#else // CONFIG_SCHED_BORE
+ if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1)
+#endif // CONFIG_SCHED_BORE
@ -298,7 +322,20 @@ index c40b775452bc..1e4ca5419a11 100644
/*
* Someone really wants this to run. If it's not unfair, run it.
*/
@@ -6615,6 +6717,9 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
se = cfs_rq->next;
- } else if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) {
+ }
+#ifdef CONFIG_SCHED_BORE
+ else if (cfs_rq->last && wakeup_preempt_entity_bscale(
+ cfs_rq->last, left, sched_bore & 2) < 1)
+#else // CONFIG_SCHED_BORE
+ else if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1)
+#endif // CONFIG_SCHED_BORE
+ {
/*
* Prefer last buddy, try to return the CPU to a preempted task.
*/
@@ -6331,6 +6455,9 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
util_est_dequeue(&rq->cfs, p);
for_each_sched_entity(se) {
@ -308,7 +345,7 @@ index c40b775452bc..1e4ca5419a11 100644
cfs_rq = cfs_rq_of(se);
dequeue_entity(cfs_rq, se, flags);
@@ -8070,7 +8175,12 @@ static unsigned long wakeup_gran(struct sched_entity *se)
@@ -7746,7 +7873,12 @@ static unsigned long wakeup_gran(struct sched_entity *se)
*
*/
static int
@ -321,28 +358,31 @@ index c40b775452bc..1e4ca5419a11 100644
{
s64 gran, vdiff = curr->vruntime - se->vruntime;
@@ -8078,11 +8188,20 @@ wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se)
@@ -7754,6 +7886,9 @@ wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se)
return -1;
gran = wakeup_gran(se);
+#ifdef CONFIG_SCHED_BORE
+ if (do_scale) gran = burst_scale(gran, se);
+ if (do_scale) gran = preempt_scale(gran, curr, se);
+#endif // CONFIG_SCHED_BORE
if (vdiff > gran)
return 1;
return 0;
}
+#ifdef CONFIG_SCHED_BORE
+static int wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se)
+{
+ return wakeup_preempt_entity_bscale(curr, se, false);
+}
+#endif // CONFIG_SCHED_BORE
@@ -7858,7 +7993,12 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
return;
static void set_last_buddy(struct sched_entity *se)
{
@@ -8430,6 +8549,9 @@ static void yield_task_fair(struct rq *rq)
update_curr(cfs_rq_of(se));
- if (wakeup_preempt_entity(se, pse) == 1) {
+#ifdef CONFIG_SCHED_BORE
+ if (wakeup_preempt_entity_bscale(se, pse, sched_bore & 2) == 1)
+#else // CONFIG_SCHED_BORE
+ if (wakeup_preempt_entity(se, pse) == 1)
+#endif // CONFIG_SCHED_BORE
+ {
/*
* Bias pick_next to pick the sched entity that is
* triggering this preemption.
@@ -8094,6 +8234,9 @@ static void yield_task_fair(struct rq *rq)
struct task_struct *curr = rq->curr;
struct cfs_rq *cfs_rq = task_cfs_rq(curr);
struct sched_entity *se = &curr->se;
@ -352,5 +392,33 @@ index c40b775452bc..1e4ca5419a11 100644
/*
* Are we the only task in the tree?
diff --git a/kernel/sched/features.h b/kernel/sched/features.h
index ee7f23c76bd3..3115bde98211 100644
--- a/kernel/sched/features.h
+++ b/kernel/sched/features.h
@@ -4,7 +4,11 @@
* them to run sooner, but does not allow tons of sleepers to
* rip the spread apart.
*/
+#ifdef CONFIG_SCHED_BORE
+SCHED_FEAT(GENTLE_FAIR_SLEEPERS, false)
+#else // CONFIG_SCHED_BORE
SCHED_FEAT(GENTLE_FAIR_SLEEPERS, true)
+#endif // CONFIG_SCHED_BORE
/*
* Place new tasks ahead so that they do not starve already running
@@ -17,7 +21,11 @@ SCHED_FEAT(START_DEBIT, true)
* wakeup-preemption), since its likely going to consume data we
* touched, increases cache locality.
*/
+#ifdef CONFIG_SCHED_BORE
+SCHED_FEAT(NEXT_BUDDY, true)
+#else // CONFIG_SCHED_BORE
SCHED_FEAT(NEXT_BUDDY, false)
+#endif // CONFIG_SCHED_BORE
/*
* Prefer to schedule the task that ran last (when we did
--
2.40.0.rc2
2.40.0

View File

@ -0,0 +1,46 @@
diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
index 5bfc0c4504608..2b781cc9082b4 100644
--- a/drivers/hid/hid-nintendo.c
+++ b/drivers/hid/hid-nintendo.c
@@ -1527,6 +1527,7 @@ static int joycon_set_rumble(struct joycon_ctlr *ctlr, u16 amp_r, u16 amp_l,
u16 freq_l_low;
u16 freq_l_high;
unsigned long flags;
+ int next_rq_head;
spin_lock_irqsave(&ctlr->lock, flags);
freq_r_low = ctlr->rumble_rl_freq;
@@ -1547,8 +1548,21 @@ static int joycon_set_rumble(struct joycon_ctlr *ctlr, u16 amp_r, u16 amp_l,
joycon_encode_rumble(data, freq_l_low, freq_l_high, amp);
spin_lock_irqsave(&ctlr->lock, flags);
- if (++ctlr->rumble_queue_head >= JC_RUMBLE_QUEUE_SIZE)
- ctlr->rumble_queue_head = 0;
+
+ next_rq_head = ctlr->rumble_queue_head + 1;
+ if (next_rq_head >= JC_RUMBLE_QUEUE_SIZE)
+ next_rq_head = 0;
+
+ /* Did we overrun the circular buffer?
+ * If so, be sure we keep the latest intended rumble state.
+ */
+ if (next_rq_head == ctlr->rumble_queue_tail) {
+ hid_dbg(ctlr->hdev, "rumble queue is full");
+ /* overwrite the prior value at the end of the circular buf */
+ next_rq_head = ctlr->rumble_queue_head;
+ }
+
+ ctlr->rumble_queue_head = next_rq_head;
memcpy(ctlr->rumble_data[ctlr->rumble_queue_head], data,
JC_RUMBLE_DATA_SIZE);
@@ -2128,7 +2142,7 @@ static int nintendo_hid_probe(struct hid_device *hdev,
ctlr->hdev = hdev;
ctlr->ctlr_state = JOYCON_CTLR_STATE_INIT;
- ctlr->rumble_queue_head = JC_RUMBLE_QUEUE_SIZE - 1;
+ ctlr->rumble_queue_head = 0;
ctlr->rumble_queue_tail = 0;
hid_set_drvdata(hdev, ctlr);
mutex_init(&ctlr->output_mutex);
generated by cgit (git 2.34.1) at 2023-04-10 17:10:33 +0000

View File

@ -0,0 +1,116 @@
diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
index 2b781cc9082b4..250f5d2f888ab 100644
--- a/drivers/hid/hid-nintendo.c
+++ b/drivers/hid/hid-nintendo.c
@@ -433,7 +433,9 @@ struct joycon_ctlr {
u8 usb_ack_match;
u8 subcmd_ack_match;
bool received_input_report;
+ unsigned int last_input_report_msecs;
unsigned int last_subcmd_sent_msecs;
+ unsigned int consecutive_valid_report_deltas;
/* factory calibration data */
struct joycon_stick_cal left_stick_cal_x;
@@ -543,19 +545,54 @@ static void joycon_wait_for_input_report(struct joycon_ctlr *ctlr)
* Sending subcommands and/or rumble data at too high a rate can cause bluetooth
* controller disconnections.
*/
+#define JC_INPUT_REPORT_MIN_DELTA 8
+#define JC_INPUT_REPORT_MAX_DELTA 17
+#define JC_SUBCMD_TX_OFFSET_MS 4
+#define JC_SUBCMD_VALID_DELTA_REQ 3
+#define JC_SUBCMD_RATE_MAX_ATTEMPTS 500
+#define JC_SUBCMD_RATE_LIMITER_USB_MS 20
+#define JC_SUBCMD_RATE_LIMITER_BT_MS 60
+#define JC_SUBCMD_RATE_LIMITER_MS(ctlr) ((ctlr)->hdev->bus == BUS_USB ? JC_SUBCMD_RATE_LIMITER_USB_MS : JC_SUBCMD_RATE_LIMITER_BT_MS)
static void joycon_enforce_subcmd_rate(struct joycon_ctlr *ctlr)
{
- static const unsigned int max_subcmd_rate_ms = 25;
- unsigned int current_ms = jiffies_to_msecs(jiffies);
- unsigned int delta_ms = current_ms - ctlr->last_subcmd_sent_msecs;
+ unsigned int current_ms;
+ unsigned long subcmd_delta;
+ int consecutive_valid_deltas = 0;
+ int attempts = 0;
+ unsigned long flags;
+
+ if (unlikely(ctlr->ctlr_state != JOYCON_CTLR_STATE_READ))
+ return;
- while (delta_ms < max_subcmd_rate_ms &&
- ctlr->ctlr_state == JOYCON_CTLR_STATE_READ) {
+ do {
joycon_wait_for_input_report(ctlr);
current_ms = jiffies_to_msecs(jiffies);
- delta_ms = current_ms - ctlr->last_subcmd_sent_msecs;
+ subcmd_delta = current_ms - ctlr->last_subcmd_sent_msecs;
+
+ spin_lock_irqsave(&ctlr->lock, flags);
+ consecutive_valid_deltas = ctlr->consecutive_valid_report_deltas;
+ spin_unlock_irqrestore(&ctlr->lock, flags);
+
+ attempts++;
+ } while ((consecutive_valid_deltas < JC_SUBCMD_VALID_DELTA_REQ ||
+ subcmd_delta < JC_SUBCMD_RATE_LIMITER_MS(ctlr)) &&
+ ctlr->ctlr_state == JOYCON_CTLR_STATE_READ &&
+ attempts < JC_SUBCMD_RATE_MAX_ATTEMPTS);
+
+ if (attempts >= JC_SUBCMD_RATE_MAX_ATTEMPTS) {
+ hid_warn(ctlr->hdev, "%s: exceeded max attempts", __func__);
+ return;
}
+
ctlr->last_subcmd_sent_msecs = current_ms;
+
+ /*
+ * Wait a short time after receiving an input report before
+ * transmitting. This should reduce odds of a TX coinciding with an RX.
+ * Minimizing concurrent BT traffic with the controller seems to lower
+ * the rate of disconnections.
+ */
+ msleep(JC_SUBCMD_TX_OFFSET_MS);
}
static int joycon_hid_send_sync(struct joycon_ctlr *ctlr, u8 *data, size_t len,
@@ -1223,6 +1260,7 @@ static void joycon_parse_report(struct joycon_ctlr *ctlr,
u8 tmp;
u32 btns;
unsigned long msecs = jiffies_to_msecs(jiffies);
+ unsigned long report_delta_ms = msecs - ctlr->last_input_report_msecs;
spin_lock_irqsave(&ctlr->lock, flags);
if (IS_ENABLED(CONFIG_NINTENDO_FF) && rep->vibrator_report &&
@@ -1364,6 +1402,31 @@ static void joycon_parse_report(struct joycon_ctlr *ctlr,
input_sync(dev);
+ spin_lock_irqsave(&ctlr->lock, flags);
+ ctlr->last_input_report_msecs = msecs;
+ /*
+ * Was this input report a reasonable time delta compared to the prior
+ * report? We use this information to decide when a safe time is to send
+ * rumble packets or subcommand packets.
+ */
+ if (report_delta_ms >= JC_INPUT_REPORT_MIN_DELTA &&
+ report_delta_ms <= JC_INPUT_REPORT_MAX_DELTA) {
+ if (ctlr->consecutive_valid_report_deltas < JC_SUBCMD_VALID_DELTA_REQ)
+ ctlr->consecutive_valid_report_deltas++;
+ } else {
+ ctlr->consecutive_valid_report_deltas = 0;
+ }
+ /*
+ * Our consecutive valid report tracking is only relevant for
+ * bluetooth-connected controllers. For USB devices, we're beholden to
+ * USB's underlying polling rate anyway. Always set to the consecutive
+ * delta requirement.
+ */
+ if (ctlr->hdev->bus == BUS_USB)
+ ctlr->consecutive_valid_report_deltas = JC_SUBCMD_VALID_DELTA_REQ;
+
+ spin_unlock_irqrestore(&ctlr->lock, flags);
+
/*
* Immediately after receiving a report is the most reliable time to
* send a subcommand to the controller. Wake any subcommand senders

View File

@ -13,6 +13,10 @@ patch -Np1 < "../patches/0003-bore.patch"
patch -Np1 < "../patches/0004-hdr.patch"
# AMD GPU USB C fix patch
patch -Np1 < "../patches/0005-amd-usbc-fix.patch"
# Nintendo controller rumble patch
patch -Np1 < "../patches/0006-Nintendo-controller-one.patch"
# Nintendo controller BT patch
patch -Np1 < "../patches/0006-Nintendo-controller-two.patch"
# Nobara patches are here: https://github.com/sammilucia/nobara-kernel-fork
# Extra Leigon laptop goodies
patch -Np1 < "../patches/0001-Add-legion-laptop-v0.1.patch"

View File

@ -2,7 +2,7 @@
echo "Pika Kernel - Getting source"
wget -nv https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.2.6.tar.gz
tar -zxf ./linux-6.2.6.tar.gz
wget -nv https://git.kernel.org/torvalds/t/linux-6.3-rc6.tar.gz
tar -zxf ./linux-6.3-rc6.tar.gz
cd linux-6.2.6
cd linux-6.3-rc6