Fix FIFO-99 abuse
Subsystems (9)
Peter Zijlstra
maintainercover Fix FIFO-99 abuse
I noticed a bunch of kthreads defaulted to FIFO-99, fix them.
The generic default is FIFO-50, the admin will have to configure the system anyway.
For some the purpose is to be above OTHER and then FIFO-1 really is sufficient.
Peter Zijlstra
maintainerPATCH 1/5 sched/pci: Reduce psimon FIFO priority
PSI defaults to a FIFO-99 thread, reduce this to FIFO-1.
FIFO-99 is the very highest priority available to SCHED_FIFO and it not a suitable default; it would indicate the psi work is the most important work on the machine.
Since Real-Time tasks will have pre-allocated memory and locked it in place, Real-Time tasks do not care about PSI. All it needs is to be above OTHER.
--- kernel/sched/psi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/psi.c +1 -1
@@ -1051,7 +1051,7 @@ struct psi_trigger *psi_trigger_create(sif (!rcu_access_pointer (group->poll_kworker)) {struct sched_param param = { - .sched_priority =MAX_RT_PRIO -1 , + .sched_priority =1 , };struct kthread_worker *kworker;
Re: [PATCH 1/5] sched/pci: Reduce psimon FIFO priority
Quoted 6 lines · Peter Zijlstra
PSI defaults to a FIFO-99 thread, reduce this to FIFO-1.
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the psi work is the most important work on the machine.
Quoted 8 lines
Since Real-Time tasks will have pre-allocated memory and locked it in place, Real-Time tasks do not care about PSI. All it needs is to be above OTHER.
Cc Suren Baghdasaryan <[email protected]>Cc Johannes Weiner <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Subject should be s/pci/psi/
Suren Baghdasaryan
maintainerRe: [PATCH 1/5] sched/pci: Reduce psimon FIFO priority
Quoted 12 lines · Johannes Weiner
Quoted 10 lines · Peter Zijlstra
PSI defaults to a FIFO-99 thread, reduce this to FIFO-1.
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the psi work is the most important work on the machine.Since Real-Time tasks will have pre-allocated memory and locked it in place, Real-Time tasks do not care about PSI. All it needs is to be above OTHER.
Quoted 8 lines
Quoted 4 lines
Cc Suren Baghdasaryan <[email protected]>Cc Johannes Weiner <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Johannes Weiner <[email protected]>Subject should be s/pci/psi/
Thanks for the patch. Please give me a couple hours for testing to ensure no regressions before merging it.
Re: [PATCH 1/5] sched/pci: Reduce psimon FIFO priority
Quoted 5 lines · Suren Baghdasaryan
Quoted 3 lines · Johannes Weiner
Quoted 1 line · Peter Zijlstra
PSI defaults to a FIFO-99 thread, reduce this to FIFO-1.
nit: above "PSI defaults" is more accurately "PSI polling defaults". The core PSI thread that handles regular updates is a regular kthread.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the psi work is the most important work on the machine.Since Real-Time tasks will have pre-allocated memory and locked it in place, Real-Time tasks do not care about PSI. All it needs is to be above OTHER.
Cc Suren Baghdasaryan <[email protected]>Cc Johannes Weiner <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Quoted 6 lines
Quoted 3 lines
Acked-by Johannes Weiner <[email protected]>Subject should be s/pci/psi/
Thanks for the patch. Please give me a couple hours for testing to ensure no regressions before merging it.
Peter Zijlstra
maintainerRe: [PATCH 1/5] sched/pci: Reduce psimon FIFO priority
In reply to Johannes WeinerQuoted 11 lines · Johannes Weiner
Quoted 10 lines · Peter Zijlstra
PSI defaults to a FIFO-99 thread, reduce this to FIFO-1.
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the psi work is the most important work on the machine.Since Real-Time tasks will have pre-allocated memory and locked it in place, Real-Time tasks do not care about PSI. All it needs is to be above OTHER.
Quoted 6 lines
Quoted 4 lines
Cc Suren Baghdasaryan <[email protected]>Cc Johannes Weiner <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Johannes Weiner <[email protected]>
Thanks!
Quoted 1 line
Subject should be s/pci/psi/
Yeah, already fixed that.. obviously one sees such typoes only after sending ;-)
Peter Zijlstra
maintainerPATCH 2/5 rcu/tree: Fix SCHED_FIFO params
In reply to Peter ZijlstraA rather embarrasing mistake had us call sched_setscheduler() before initializing the parameters passed to it.
--- kernel/rcu/tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/rcu/tree.c +3 -3
@@ -3234,13 +3234,13 @@ static int __init rcu_spawn_gp_kthread(v t =kthread_create (rcu_gp_kthread,NULL ,"%s" , rcu_state.name);if (WARN_ONCE (IS_ERR (t),"%s: Could not start grace-period kthread, OOM is now expected behavior\n" , __func__))return 0 ; -if (kthread_prio) +if (kthread_prio) { + sp.sched_priority = kthread_prio;sched_setscheduler_nocheck (t,SCHED_FIFO , &sp); + } rnp =rcu_get_root ();raw_spin_lock_irqsave_rcu_node (rnp, flags); rcu_state.gp_kthread = t; -if (kthread_prio) - sp.sched_priority = kthread_prio;raw_spin_unlock_irqrestore_rcu_node (rnp, flags);wake_up_process (t);rcu_spawn_nocb_kthreads ();
Re: [PATCH 2/5] rcu/tree: Fix SCHED_FIFO params
Quoted 5 lines · Peter Zijlstra
A rather embarrasing mistake had us call
sched_setscheduler()before initializing the parameters passed to it.Cc Juri Lelli <[email protected]>Cc "Paul E. McKenney" <[email protected]>
Thank you for having CCed me this time. ;-)
Quoted 27 lines
Fixes 1a763fd7c633 ("rcu/tree: Call setschedule() gp ktread to SCHED_FIFO outside of atomic region")Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- kernel/rcu/tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)kernel/rcu/tree.c +3
-3@@ -3234,13 +3234,13 @@ static int __init rcu_spawn_gp_kthread(v t =kthread_create (rcu_gp_kthread,NULL ,"%s" , rcu_state.name);if (WARN_ONCE (IS_ERR (t),"%s: Could not start grace-period kthread, OOM is now expected behavior\n" , __func__))return 0 ; -if (kthread_prio) +if (kthread_prio) { + sp.sched_priority = kthread_prio;sched_setscheduler_nocheck (t,SCHED_FIFO , &sp); + } rnp =rcu_get_root ();raw_spin_lock_irqsave_rcu_node (rnp, flags); rcu_state.gp_kthread = t; -if (kthread_prio) - sp.sched_priority = kthread_prio;raw_spin_unlock_irqrestore_rcu_node (rnp, flags);wake_up_process (t);rcu_spawn_nocb_kthreads ();
Peter Zijlstra
maintainerRe: [PATCH 2/5] rcu/tree: Fix SCHED_FIFO params
Quoted 8 lines · Paul E. McKenney
Quoted 5 lines · Peter Zijlstra
A rather embarrasing mistake had us call
sched_setscheduler()before initializing the parameters passed to it.Cc Juri Lelli <[email protected]>Cc "Paul E. McKenney" <[email protected]>Thank you for having CCed me this time. ;-)
Yeah, pretty much everything about that last time seems to have gone wrong...
Re: [PATCH 2/5] rcu/tree: Fix SCHED_FIFO params
Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Paul E. McKenney
Quoted 3 lines · Peter Zijlstra
A rather embarrasing mistake had us call
sched_setscheduler()before initializing the parameters passed to it.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Cc Juri Lelli <[email protected]>Cc "Paul E. McKenney" <[email protected]>Thank you for having CCed me this time. ;-)
Yeah, pretty much everything about that last time seems to have gone wrong...
Not that I necessarily would have spotted the bug, mind you...
Thanx, Paul
Peter Zijlstra
maintainerPATCH 3/5 crypto: Reduce default RT priority
In reply to Peter ZijlstraThe crypto engine initializes its kworker thread to FIFO-99 (when requesting RT priority), reduce this to FIFO-50.
FIFO-99 is the very highest priority available to SCHED_FIFO and it not a suitable default; it would indicate the crypto work is the most important work on the machine.
--- crypto/crypto_engine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/crypto_engine.c +1 -1
@@ -425,7 +425,7 @@ EXPORT_SYMBOL_GPL(crypto_engine_stop);*/ struct crypto_engine *crypto_engine_alloc_init (struct device *dev,bool rt) { -struct sched_param param = { .sched_priority =MAX_RT_PRIO -1 }; +struct sched_param param = { .sched_priority =MAX_RT_PRIO /2 };struct crypto_engine *engine;if (!dev)
Herbert Xu
maintainerRe: [PATCH 3/5] crypto: Reduce default RT priority
Quoted 13 lines · Peter Zijlstra
The crypto engine initializes its kworker thread to FIFO-99 (when requesting RT priority), reduce this to FIFO-50.
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the crypto work is the most important work on the machine.Cc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Quoted 3 lines
--- crypto/crypto_engine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Peter Zijlstra
maintainerPATCH 4/5 media/ivtv: Reduce default FIFO priority
In reply to Peter ZijlstraThe ivtv driver creates a FIFO-99 thread by default, reduce this to FIFO-1.
FIFO-99 is the very highest priority available to SCHED_FIFO and it not a suitable default; it would indicate the ivtv work is the most important work on the machine.
FIFO-1 gets it above all OTHER tasks, which seems high enough lacking better justification.
--- drivers/media/pci/ivtv/ivtv-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/ivtv/ivtv-driver.c +1 -1
@@ -738,7 +738,7 @@ static void ivtv_process_options(struct*/ static int ivtv_init_struct1 (struct ivtv *itv) { -struct sched_param param = { .sched_priority =99 }; +struct sched_param param = { .sched_priority =1 }; itv->base_addr =pci_resource_start (itv->pdev,0 ); itv->enc_mbox.max_mbox =2 ;/* the encoder has 3 mailboxes (0-2) */
Re: [PATCH 4/5] media/ivtv: Reduce default FIFO priority
Hi Peter:
Quoted 6 lines · Peter Zijlstra
The ivtv driver creates a FIFO-99 thread by default, reduce this to FIFO-1.
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the ivtv work is the most important work on the machine.
ivtv based boards are legacy, convential PCI boards. At this point, these old boards are generally installed in boxes dedicated to video capture (e.g. MythTV setups) or boxes dedicated to capturing VBI information, like closed captioning, for business intelligence.
For boxes dedicated to video or VBI capture, the ivtv work may very well be close to the most important work on the machine, to avoid dropping video frames or VBI data.
Quoted 2 lines
FIFO-1 gets it above all OTHER tasks, which seems high enough lacking better justification.
I agree that FIFO-99 is the wrong default level.
However, in my opinion, threads responsible for real time data acquisition should have higher priority than the other kernel driver threads normally running at FIFO-50.
How about FIFO-51 as the default?
Regards,
Andy
Quoted 24 lines
Cc Andy Walls <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- drivers/media/pci/ivtv/ivtv-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/pci/ivtv/ivtv-driver.c +1
-1@@ -738,7 +738,7 @@ static void ivtv_process_options(struct*/ static int ivtv_init_struct1 (struct ivtv *itv) { -struct sched_param param = { .sched_priority =99 }; +struct sched_param param = { .sched_priority =1 }; itv->base_addr =pci_resource_start (itv->pdev,0 ); itv->enc_mbox.max_mbox =2 ;/* the encoder has 3 mailboxes (0- 2) */
Peter Zijlstra
maintainerRe: [PATCH 4/5] media/ivtv: Reduce default FIFO priority
Quoted 23 lines · Andy Walls
Hi Peter:
Quoted 6 lines · Peter Zijlstra
The ivtv driver creates a FIFO-99 thread by default, reduce this to FIFO-1.
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the ivtv work is the most important work on the machine.ivtv based boards are legacy, convential PCI boards. At this point, these old boards are generally installed in boxes dedicated to video capture (e.g. MythTV setups) or boxes dedicated to capturing VBI information, like closed captioning, for business intelligence.
For boxes dedicated to video or VBI capture, the ivtv work may very well be close to the most important work on the machine, to avoid dropping video frames or VBI data.
Quoted 2 lines
FIFO-1 gets it above all OTHER tasks, which seems high enough lacking better justification.
Quoted 7 lines
I agree that FIFO-99 is the wrong default level.
However, in my opinion, threads responsible for real time data acquisition should have higher priority than the other kernel driver threads normally running at FIFO-50.
How about FIFO-51 as the default?
If the consumer of the data are RT tasks as well (I hadn't expected that from a TV capture device) then I'd propose to use FIFO-50 as default.
The thing is, the moment you're doing actual proper RT, the admin needs to configure things anyway, which then very much includes setting the priority of interrupt threads and the like.
(that is exacty why pretty much everything defaults to FIFO-50)
Peter Zijlstra
maintainerRe: [PATCH 4/5] media/ivtv: Reduce default FIFO priority
Quoted 8 lines · Peter Zijlstra
If the consumer of the data are RT tasks as well (I hadn't expected that from a TV capture device) then I'd propose to use FIFO-50 as default.
The thing is, the moment you're doing actual proper RT, the admin needs to configure things anyway, which then very much includes setting the priority of interrupt threads and the like.
(that is exacty why pretty much everything defaults to FIFO-50)
Is the below acceptible?
---
Subject: media/ivtv: Reduce default FIFO priority
From: Peter Zijlstra <[email protected]>
Date: Thu Aug 1 12:56:40 CEST 2019
The ivtv driver creates a FIFO-99 thread by default, reduce this to FIFO-50.
FIFO-99 is the very highest priority available to SCHED_FIFO and it not a suitable default; it would indicate the ivtv work is the most important work on the machine.
--- drivers/media/pci/ivtv/ivtv-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/ivtv/ivtv-driver.c +1 -1
@@ -738,7 +738,7 @@ static void ivtv_process_options(struct*/ static int ivtv_init_struct1 (struct ivtv *itv) { -struct sched_param param = { .sched_priority =99 }; +struct sched_param param = { .sched_priority =MAX_RT_PRIO /2 }; itv->base_addr =pci_resource_start (itv->pdev,0 ); itv->enc_mbox.max_mbox =2 ;/* the encoder has 3 mailboxes (0-2) */
Re: [PATCH 4/5] media/ivtv: Reduce default FIFO priority
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · Peter Zijlstra
If the consumer of the data are RT tasks as well (I hadn't expected that from a TV capture device) then I'd propose to use FIFO-50 as default.
The thing is, the moment you're doing actual proper RT, the admin needs to configure things anyway, which then very much includes setting the priority of interrupt threads and the like.
(that is exacty why pretty much everything defaults to FIFO-50)
Is the below acceptible?
I think this should be OK. ivtv is real-time sensitive since certain tasks have to happen within (if I remember correctly) 1/60th of a second (the time it takes to capture a single video field). Data is lost if it can't be done within that time.
Using FIFO-50 means that it competes with other irq threads, and since irq threads shouldn't take up much time anyway this should be OK.
Andy, what do you think?
Regards,
Hans
Quoted 35 lines
---
Subject: media/ivtv: Reduce default FIFO priority
From: Peter Zijlstra <[email protected]>
Date: Thu Aug 1 12:56:40 CEST 2019The ivtv driver creates a FIFO-99 thread by default, reduce this to FIFO-50.
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the ivtv work is the most important work on the machine.Cc Andy Walls <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- drivers/media/pci/ivtv/ivtv-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/pci/ivtv/ivtv-driver.c +1
-1@@ -738,7 +738,7 @@ static void ivtv_process_options(struct*/ static int ivtv_init_struct1 (struct ivtv *itv) { -struct sched_param param = { .sched_priority =99 }; +struct sched_param param = { .sched_priority =MAX_RT_PRIO /2 }; itv->base_addr =pci_resource_start (itv->pdev,0 ); itv->enc_mbox.max_mbox =2 ;/* the encoder has 3 mailboxes (0-2) */
Peter Zijlstra
maintainerPATCH 5/5 spi: Reduce kthread priority
In reply to Peter ZijlstraThe SPI thingies request FIFO-99 by default, reduce this to FIFO-50.
FIFO-99 is the very highest priority available to SCHED_FIFO and it not a suitable default; it would indicate the SPI work is the most important work on the machine.
--- drivers/platform/chrome/cros_ec_spi.c | 2 +- drivers/spi/spi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_spi.c +1 -1
@@ -706,7 +706,7 @@ static int cros_ec_spi_devm_high_pri_all struct cros_ec_spi *ec_spi) {struct sched_param sched_priority = { - .sched_priority =MAX_RT_PRIO -1 , + .sched_priority =MAX_RT_PRIO /2 , };int err;
drivers/spi/spi.c +1 -1
@@ -1434,7 +1434,7 @@ static void spi_pump_messages(struct kth*/ static void spi_set_thread_rt (struct spi_controller *ctlr) { -struct sched_param param = { .sched_priority =MAX_RT_PRIO -1 }; +struct sched_param param = { .sched_priority =MAX_RT_PRIO /2 };dev_info (&ctlr->dev,"will run message pump with realtime priority\n" );
Mark Brown
maintainerRe: [PATCH 5/5] spi: Reduce kthread priority
Quoted 1 line · Peter Zijlstra
The SPI thingies request FIFO-99 by default, reduce this to FIFO-50.
I don't have a cover letter or any other context, what's going on here with dependencies?
Peter Zijlstra
maintainerRe: [PATCH 5/5] spi: Reduce kthread priority
Quoted 6 lines · Mark Brown
Quoted 1 line · Peter Zijlstra
The SPI thingies request FIFO-99 by default, reduce this to FIFO-50.
I don't have a cover letter or any other context, what's going on here with dependencies?
Patch stands on it own. I just went through the tree looking for FIFO (ab)users.
Re: [PATCH 5/5] spi: Reduce kthread priority
In reply to Peter ZijlstraHi Peter,
Quoted 21 lines · Peter Zijlstra
The SPI thingies request FIFO-99 by default, reduce this to FIFO-50.
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the SPI work is the most important work on the machine.Cc Benson Leung <[email protected]>Cc Enric Balletbo i Serra <[email protected]>Cc Guenter Roeck <[email protected]>Cc Mark Brown <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- drivers/platform/chrome/cros_ec_spi.c | 2 +- drivers/spi/spi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_spi.c static int cros_ec_spi_devm_high_pri_all · line 709
Quoted 5 lines
drivers/platform/chrome/cros_ec_spi.c +1
-1@@ -706,7 +706,7 @@ static int cros_ec_spi_devm_high_pri_all struct cros_ec_spi *ec_spi) {struct sched_param sched_priority = { - .sched_priority =MAX_RT_PRIO -1 , + .sched_priority =MAX_RT_PRIO /2 ,
include/linux/sched/prio.h says:
* Priority of a process goes from 0..MAX_PRIO-1, valid RT
* priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
* tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
* values are inverted: lower p->prio value means higher priority.
So the new 50 is actually a higher priority than the old 99?
Given I'm far from an RT expert, I must be missing something? Thanks!
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Peter Zijlstra
maintainerRe: [PATCH 5/5] spi: Reduce kthread priority
Quoted 37 lines · Geert Uytterhoeven
Hi Peter,
Quoted 21 lines · Peter Zijlstra
The SPI thingies request FIFO-99 by default, reduce this to FIFO-50.
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the SPI work is the most important work on the machine.Cc Benson Leung <[email protected]>Cc Enric Balletbo i Serra <[email protected]>Cc Guenter Roeck <[email protected]>Cc Mark Brown <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- drivers/platform/chrome/cros_ec_spi.c | 2 +- drivers/spi/spi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/platform/chrome/cros_ec_spi.c static int cros_ec_spi_devm_high_pri_all · line 709
Quoted 5 lines
drivers/platform/chrome/cros_ec_spi.c +1
-1@@ -706,7 +706,7 @@ static int cros_ec_spi_devm_high_pri_all struct cros_ec_spi *ec_spi) {struct sched_param sched_priority = { - .sched_priority =MAX_RT_PRIO -1 , + .sched_priority =MAX_RT_PRIO /2 ,
include/linux/sched/prio.hsays:* Priority of a process goes from 0..MAX_PRIO-1, valid RT
* priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
* tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
* values are inverted: lowerp->priovalue means higher priority.
Quoted 4 lines
So the new 50 is actually a higher priority than the old 99?
Given I'm far from an RT expert, I must be missing something? Thanks!
Ah; you found the confusion ;-)
https://lkml.kernel.org/[email protected]
But basically, user-space prio is [1-99], while in-kernel prio is [0-98]. The above is user prio (it basically uses the sched_setscheduler() syscall).
So 50 really is lower than 99.
Re: [PATCH 5/5] spi: Reduce kthread priority
Hi Peter,
Quoted 36 lines · Peter Zijlstra
Quoted 35 lines · Geert Uytterhoeven
Quoted 21 lines · Peter Zijlstra
The SPI thingies request FIFO-99 by default, reduce this to FIFO-50.
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the SPI work is the most important work on the machine.Cc Benson Leung <[email protected]>Cc Enric Balletbo i Serra <[email protected]>Cc Guenter Roeck <[email protected]>Cc Mark Brown <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- drivers/platform/chrome/cros_ec_spi.c | 2 +- drivers/spi/spi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/platform/chrome/cros_ec_spi.c static int cros_ec_spi_devm_high_pri_all · line 709
Quoted 5 lines
drivers/platform/chrome/cros_ec_spi.c +1
-1@@ -706,7 +706,7 @@ static int cros_ec_spi_devm_high_pri_all struct cros_ec_spi *ec_spi) {struct sched_param sched_priority = { - .sched_priority =MAX_RT_PRIO -1 , + .sched_priority =MAX_RT_PRIO /2 ,
include/linux/sched/prio.hsays:* Priority of a process goes from 0..MAX_PRIO-1, valid RT
* priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
* tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
* values are inverted: lowerp->priovalue means higher priority.
Quoted 8 lines
Quoted 4 lines
So the new 50 is actually a higher priority than the old 99?
Given I'm far from an RT expert, I must be missing something? Thanks!
Ah; you found the confusion ;-)
/me adds /r after org/
Thanks!
Quoted 5 lines
But basically, user-space prio is [1-99], while in-kernel prio is [0-98]. The above is user prio (it basically uses the
sched_setscheduler()syscall).So 50 really is lower than 99.
IC.
BTW, what about having a #define for MAX_RT_PRIO / 2?
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH 5/5] spi: Reduce kthread priority
In reply to Peter Zijlstracc'ing Doug as he might be really interested on this patch
Quoted 2 lines · Peter Zijlstra
The SPI thingies request FIFO-99 by default, reduce this to FIFO-50.
You say below that is not a suitable default but there is any other reason? Did you observed problems with this?
Quoted 40 lines
FIFO-99 is the very highest priority available to
SCHED_FIFOand it not a suitable default; it would indicate the SPI work is the most important work on the machine.Cc Benson Leung <[email protected]>Cc Enric Balletbo i Serra <[email protected]>Cc Guenter Roeck <[email protected]>Cc Mark Brown <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- drivers/platform/chrome/cros_ec_spi.c | 2 +- drivers/spi/spi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/platform/chrome/cros_ec_spi.c +1
-1@@ -706,7 +706,7 @@ static int cros_ec_spi_devm_high_pri_all struct cros_ec_spi *ec_spi) {struct sched_param sched_priority = { - .sched_priority =MAX_RT_PRIO -1 , + .sched_priority =MAX_RT_PRIO /2 , };int err;drivers/spi/spi.c +1
-1@@ -1434,7 +1434,7 @@ static void spi_pump_messages(struct kth*/ static void spi_set_thread_rt (struct spi_controller *ctlr) { -struct sched_param param = { .sched_priority =MAX_RT_PRIO -1 }; +struct sched_param param = { .sched_priority =MAX_RT_PRIO /2 };dev_info (&ctlr->dev,"will run message pump with realtime priority\n" );
Peter Zijlstra
maintainerRe: [PATCH 5/5] spi: Reduce kthread priority
Quoted 9 lines · Enric Balletbo i Serra
cc'ing Doug as he might be really interested on this patch
Quoted 2 lines · Peter Zijlstra
The SPI thingies request FIFO-99 by default, reduce this to FIFO-50.
You say below that is not a suitable default but there is any other reason? Did you observed problems with this?
I didn't observe any problems with it personally. But imagine your device is used to control something critical, like something leathal, say a bandsaw. And just as you stick your hand through the laser guarding it, your SPI device chirps and preempts the task that was about to pull the emergency break and save your hand.
FIFO-99 is the highest possible prio (for SCHED_FIFO) and by using it you say your task is the utmost imporant task on the system.
I'm thinking that isn't true 99% of the time, except of course when that bandsaw emergency break is attached through SPI, but in that case the admin can very well chrt the prio of this thread.
Mark Brown
maintainerRe: [PATCH 5/5] spi: Reduce kthread priority
Quoted 3 lines · Peter Zijlstra
I'm thinking that isn't true 99% of the time, except of course when that bandsaw emergency break is attached through SPI, but in that case the admin can very well chrt the prio of this thread.
The SPI thread isn't usually RT, it's only made RT if something in the system asks for it - the reason the ChromeOS people got CCed in is that some of their embedded controllers are very fragile and need super tight timing on some of the interactions over their control interface so they're one of the users here. Of course everyone is then going to claim that their usage is the most critical usage in the system, and they may well even be right, but I do tend to agree that just any old RT priority is probably a sensible default since for most cases there will be few if any other RT tasks anyway.
Doug Anderson
Reviewed-by Douglas AndersonRe: [PATCH 5/5] spi: Reduce kthread priority
Hi,
Quoted 7 lines · Mark Brown
Quoted 3 lines · Peter Zijlstra
I'm thinking that isn't true 99% of the time, except of course when that bandsaw emergency break is attached through SPI, but in that case the admin can very well chrt the prio of this thread.
Quoted 9 lines
The SPI thread isn't usually RT, it's only made RT if something in the system asks for it - the reason the ChromeOS people got CCed in is that some of their embedded controllers are very fragile and need super tight timing on some of the interactions over their control interface so they're one of the users here. Of course everyone is then going to claim that their usage is the most critical usage in the system, and they may well even be right, but I do tend to agree that just any old RT priority is probably a sensible default since for most cases there will be few if any other RT tasks anyway.
For the Chrome OS case I believe that "MAX_RT_PRIO / 2" should be just fine. In fact in an earlier version of my work to make CrOS EC work better at <https://crrev.com/c/1603464> I had said "We'll arbitrarily pick a priority of "MAX_RT_PRIO / 4 - 1", AKA 24. This seems to work fine in practice." I only switched to "MAX_RT_PRIO - 1" to match the SPI code.
Mostly we just need to be a bit higher than things that request the highest non-realtime priority, notably DM Crypt and loopback which both schedule a bunch of work on the high priority system workqueue. Those two things in particular seem to want high priority for performance reasons but not for correctness reasons. As mentioned earlier our EC will actually fail transfers if there is too much delay.
Thus:
Mark Brown
maintainerApplied "spi: Reduce kthread priority" to the spi tree
In reply to Peter ZijlstraThe patch
spi: Reduce kthread priority
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-5.4
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
4ff13d00ebd5533947b083c66d44da3243a2d559Mon Sep 17 00:00:00 2001
From: Peter Zijlstra <[email protected]>
Date: Thu, 1 Aug 2019 13:13:53 +0200
Subject: [PATCH] spi: Reduce kthread priority
The SPI thingies request FIFO-99 by default, reduce this to FIFO-50.
FIFO-99 is the very highest priority available to SCHED_FIFO and it not a suitable default; it would indicate the SPI work is the most important work on the machine.
--- drivers/platform/chrome/cros_ec_spi.c | 2 +- drivers/spi/spi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/platform/chrome/cros_ec_spi.c +1 -1
@@ -706,7 +706,7 @@ static int cros_ec_spi_devm_high_pri_alloc(struct device *dev, struct cros_ec_spi *ec_spi) {struct sched_param sched_priority = { - .sched_priority =MAX_RT_PRIO -1 , + .sched_priority =MAX_RT_PRIO /2 , };int err;
drivers/spi/spi.c +1 -1
@@ -1434,7 +1434,7 @@ static void spi_pump_messages(struct kthread_work *work)*/ static void spi_set_thread_rt (struct spi_controller *ctlr) { -struct sched_param param = { .sched_priority =MAX_RT_PRIO -1 }; +struct sched_param param = { .sched_priority =MAX_RT_PRIO /2 };dev_info (&ctlr->dev,"will run message pump with realtime priority\n" );
Signature · 1 line
2.20.1
Quoted 6 lines · Peter Zijlstra
I noticed a bunch of kthreads defaulted to FIFO-99, fix them.
The generic default is FIFO-50, the admin will have to configure the system anyway.
For some the purpose is to be above OTHER and then FIFO-1 really is sufficient.
I was looking in this area too and was thinking of a way to consolidate the creation of RT/DL tasks in the kernel and the way we set the priority.
Does it make sense to create a new header for RT priorities for kthreads created in the kernel so that we can easily track and rationale about the relative priorities of in-kernel RT tasks?
When working in the FW world such a header helped a lot in understanding what runs at each priority level and how to reason about what priority level makes sense for a new item. It could be a nice single point of reference; even for admins.
Cheers
--
Qais Yousef
Peter Zijlstra
maintainerQuoted 11 lines · Qais Yousef
Quoted 6 lines · Peter Zijlstra
I noticed a bunch of kthreads defaulted to FIFO-99, fix them.
The generic default is FIFO-50, the admin will have to configure the system anyway.
For some the purpose is to be above OTHER and then FIFO-1 really is sufficient.
I was looking in this area too and was thinking of a way to consolidate the creation of RT/DL tasks in the kernel and the way we set the priority.
Quoted 8 lines
Does it make sense to create a new header for RT priorities for kthreads created in the kernel so that we can easily track and rationale about the relative priorities of in-kernel RT tasks?
When working in the FW world such a header helped a lot in understanding what runs at each priority level and how to reason about what priority level makes sense for a new item. It could be a nice single point of reference; even for admins.
Well, SCHED_FIFO is a broken scheduler model; that is, it is fundamentally incapable of resource management, which is the one thing an OS really should be doing.
This is of course the reason it is limited to privileged users only.
Worse still; it is fundamentally impossible to compose static priority workloads. You cannot take two correctly working static prio workloads and smash them together and still expect them to work.
For this reason 'all' FIFO tasks the kernel creates are basically at:
MAX_RT_PRIO / 2
The administrator _MUST_ configure the system, the kernel simply doesn't know enough information to make a sensible choice.
Now, Geert suggested so make make a define for that, but how about we do something like:
/*
* ${the above explanation}
*/
int kernel_setscheduler_fifo(struct task_struct *p)
{
struct sched_param sp = { .sched_priority = MAX_RT_PRIO / 2 };
return sched_setscheduler_nocheck(p, SCHED_FIFO, &sp);
}And then take away sched_setscheduler*().
Quoted 45 lines · Peter Zijlstra
Quoted 11 lines · Qais Yousef
Quoted 6 lines · Peter Zijlstra
I noticed a bunch of kthreads defaulted to FIFO-99, fix them.
The generic default is FIFO-50, the admin will have to configure the system anyway.
For some the purpose is to be above OTHER and then FIFO-1 really is sufficient.
I was looking in this area too and was thinking of a way to consolidate the creation of RT/DL tasks in the kernel and the way we set the priority.
Quoted 8 lines
Does it make sense to create a new header for RT priorities for kthreads created in the kernel so that we can easily track and rationale about the relative priorities of in-kernel RT tasks?
When working in the FW world such a header helped a lot in understanding what runs at each priority level and how to reason about what priority level makes sense for a new item. It could be a nice single point of reference; even for admins.
Well,
SCHED_FIFOis a broken scheduler model; that is, it is fundamentally incapable of resource management, which is the one thing an OS really should be doing.This is of course the reason it is limited to privileged users only.
Worse still; it is fundamentally impossible to compose static priority workloads. You cannot take two correctly working static prio workloads and smash them together and still expect them to work.
For this reason 'all' FIFO tasks the kernel creates are basically at:
MAX_RT_PRIO/ 2The administrator _MUST_ configure the system, the kernel simply doesn't know enough information to make a sensible choice.
Now, Geert suggested so make make a define for that, but how about we do something like:
/*
* ${the above explanation}
*/
intkernel_setscheduler_fifo(struct task_struct *p)
Quoted 6 lines
{ struct sched_param sp = { .sched_priority = MAX_RT_PRIO / 2 }; return sched_setscheduler_nocheck(p, SCHED_FIFO, &sp); }And then take away sched_setscheduler*().
Yes, please.
tglx
Quoted 45 lines · Peter Zijlstra
Quoted 11 lines · Qais Yousef
Quoted 6 lines · Peter Zijlstra
I noticed a bunch of kthreads defaulted to FIFO-99, fix them.
The generic default is FIFO-50, the admin will have to configure the system anyway.
For some the purpose is to be above OTHER and then FIFO-1 really is sufficient.
I was looking in this area too and was thinking of a way to consolidate the creation of RT/DL tasks in the kernel and the way we set the priority.
Quoted 8 lines
Does it make sense to create a new header for RT priorities for kthreads created in the kernel so that we can easily track and rationale about the relative priorities of in-kernel RT tasks?
When working in the FW world such a header helped a lot in understanding what runs at each priority level and how to reason about what priority level makes sense for a new item. It could be a nice single point of reference; even for admins.
Well,
SCHED_FIFOis a broken scheduler model; that is, it is fundamentally incapable of resource management, which is the one thing an OS really should be doing.This is of course the reason it is limited to privileged users only.
Worse still; it is fundamentally impossible to compose static priority workloads. You cannot take two correctly working static prio workloads and smash them together and still expect them to work.
For this reason 'all' FIFO tasks the kernel creates are basically at:
MAX_RT_PRIO/ 2The administrator _MUST_ configure the system, the kernel simply doesn't know enough information to make a sensible choice.
Now, Geert suggested so make make a define for that, but how about we do something like:
/*
* ${the above explanation}
*/
intkernel_setscheduler_fifo(struct task_struct *p)
Quoted 6 lines
{ struct sched_param sp = { .sched_priority = MAX_RT_PRIO / 2 }; return sched_setscheduler_nocheck(p, SCHED_FIFO, &sp); }And then take away sched_setscheduler*().
Yes a somewhat enforced default makes more sense to me. I assume you no longer want to put the kthreads that just need to be above OTHER in FIFO-1?
While at it, since we will cram all kthreads on the same priority, isn't a SCHED_RR a better choice now? I think the probability of a clash is pretty low, but when it happens, shouldn't we try to guarantee some fairness?
--
Qais Yousef
Peter Zijlstra
maintainerQuoted 2 lines · Qais Yousef
Yes a somewhat enforced default makes more sense to me. I assume you no longer want to put the kthreads that just need to be above OTHER in FIFO-1?
I'm not sure, maybe, there's not that many of them, but possibly we add another interface for them.
Quoted 3 lines
While at it, since we will cram all kthreads on the same priority, isn't a
SCHED_RRa better choice now? I think the probability of a clash is pretty low, but when it happens, shouldn't we try to guarantee some fairness?
It's never been a problem, and aside from these few straggler threads, everybody has effectively been there already for years, so if it were a problem someone would've complained by now.
Also; like said before, the admin had better configure.
Also also, RR-SMP is actually broken (and nobody has cared enough to bother fixing it).
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Qais Yousef
Yes a somewhat enforced default makes more sense to me. I assume you no longer want to put the kthreads that just need to be above OTHER in FIFO-1?
I'm not sure, maybe, there's not that many of them, but possibly we add another interface for them.
By the way, did you see this one which is set to priority 16?
https://elixir.bootlin.com/linux/v5.3-rc2/source/drivers/gpu/drm/msm/msm_drv.c#L523
Quoted 8 lines
Quoted 4 lines
While at it, since we will cram all kthreads on the same priority, isn't a
SCHED_RRa better choice now? I think the probability of a clash is pretty low, but when it happens, shouldn't we try to guarantee some fairness?It's never been a problem, and aside from these few straggler threads, everybody has effectively been there already for years, so if it were a problem someone would've complained by now.
Usually they can run on enough CPUs so a real clash is definitely hard.
I'm trying to collect data on that, if I find something interesting I'll share it.
Quoted 2 lines
Also; like said before, the admin had better configure.
I agree. But I don't think an 'admin' is an easily defined entity for all systems. On mobile, is it the SoC vendor, Android framework, or the handset/platform vendor/integrator?
In a *real* realtime system I think things are better defined. But usage of RT tasks on generic systems is the confusing part. There's no real ownership and things are more ad-hoc.
Quoted 3 lines
Also also, RR-SMP is actually broken (and nobody has cared enough to bother fixing it).
If you can give me enough pointers to understand the problem I might be able to bother with it :-)
Thanks
--
Qais Yousef
Peter Zijlstra
maintainerQuoted 6 lines · Qais Yousef
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Qais Yousef
Yes a somewhat enforced default makes more sense to me. I assume you no longer want to put the kthreads that just need to be above OTHER in FIFO-1?
Quoted 6 lines
Quoted 2 lines
I'm not sure, maybe, there's not that many of them, but possibly we add another interface for them.
By the way, did you see this one which is set to priority 16?
https://elixir.bootlin.com/linux/v5.3-rc2/source/drivers/gpu/drm/msm/msm_drv.c#L523
I did, I ignored it because it wasn't 99 or something silly like that, but I'd definitely mop it up when doing the proposed.
Quoted 5 lines
Quoted 1 line
Also; like said before, the admin had better configure.
I agree. But I don't think an 'admin' is an easily defined entity for all systems. On mobile, is it the SoC vendor, Android framework, or the handset/platform vendor/integrator?
Mostly Android I suspect, but if SoC specific drivers have RT threads, it's their responsibility to integrate properly with the rest of Android of course.
Quoted 5 lines
Quoted 2 lines
Also also, RR-SMP is actually broken (and nobody has cared enough to bother fixing it).
If you can give me enough pointers to understand the problem I might be able to bother with it :-)
So the push-pull balancer we have (designed for FIFO but also applied to RR) will only move a task if the destination CPU has a lower prio. In the case where one CPU has 3 tasks and the other 1, and they're all the same prio, it does nothing. For FIFO that is fine, for RR, not so much.
Because then the one CPU will RR between 3 tasks, giving each task 1/3rd, while the other will only run the one task.
Quoted 6 lines · Peter Zijlstra
Quoted 5 lines
Quoted 2 lines
Also also, RR-SMP is actually broken (and nobody has cared enough to bother fixing it).
If you can give me enough pointers to understand the problem I might be able to bother with it :-)
Quoted 7 lines
So the push-pull balancer we have (designed for FIFO but also applied to RR) will only move a task if the destination CPU has a lower prio. In the case where one CPU has 3 tasks and the other 1, and they're all the same prio, it does nothing. For FIFO that is fine, for RR, not so much.
Because then the one CPU will RR between 3 tasks, giving each task 1/3rd, while the other will only run the one task.
Okay so what we need to do is keep a count of number of RR tasks on each CPU (which we already do IIRC) and take that into account in find_loweset_rq()/cpupri_find().
Let me see if I can create a test case then hack something.
Thanks
--
Qais Yousef