cobalt/select: replace APC with irq_work
Quoted 10 lines · On 24.09.20 08:54, hongzha1 wrote:
schedule
irq_workwhich is to schedule work to execute heavyxnselector_destroy_loopinstead of calling__xnapc_schedule.Signed-off-by hongzha1 <[email protected]>---
this patch is for wip/dovetail. This is new version. It would scheduleirq_workwhich is to schedule work to execute heavyxnselector_destroy_loopbut not execute it inirq_workdirectly instead of calling__xnapc_schedule.
What is the benefit of this indirection to a workqueue? irq_work - as hardened by dovetail for triggering from oob / xenomai context - still run the work in in-band / Linux context, just in an interrupt. IIRC, that is the same with the previous APC mechanism, so a 1:1 match.
Quoted 122 lines
kernel/cobalt/select.c +79
-10@@ -23,7 +23,75 @@#include <cobalt/kernel/sched.h> #include <cobalt/kernel/synch.h> #include <cobalt/kernel/select.h> -#include <cobalt/kernel/apc.h> +#include <linux/irq_work.h> + +static bool cobalt_select_isinit; +static LIST_HEAD (xnselect_work_queue); + +typedef void (*cobalt_select_destroy_t ) (void *cookie); + +struct cobalt_select_work { +cobalt_select_destroy_t handler; +void *arg; +struct work_struct destroy_task; +}; + +typedef struct cobalt_select_work cobalt_select_work_t ; + +static cobalt_select_work_t xndeletion_work; + +static void do_xnselect_work (struct irq_work *work) +{ +struct work_struct *xnselect_work; +spl_t s; + +xnlock_get_irqsave (&nklock, s); +while (!list_empty (&xnselect_work_queue)) { + xnselect_work =list_first_entry (&xnselect_work_queue, + struct work_struct, entry); +list_del_init (&xnselect_work->entry); +xnlock_put_irqrestore (&nklock, s); + +schedule_work (xnselect_work); + +xnlock_get_irqsave (&nklock, s); + + } +xnlock_put_irqrestore (&nklock, s); + +} + +static DEFINE_IRQ_WORK(xnselect_irq_work, do_xnselect_work); + +typedef void (*cobalt_select_destroy_t )(void *cookie); + +void xnselect_schedule_work (struct work_struct *destroy_work) +{ +spl_t s; + +xnlock_get_irqsave (&nklock, s); +list_add_tail (&xnselect_work_queue, &destroy_work->entry); +xnlock_put_irqrestore (&nklock, s); + +irq_work_queue (&xnselect_irq_work); +} + +static void cobalt_select_execute (struct work_struct *work) +{ +cobalt_select_work_t *xnselect = +container_of (work, cobalt_select_work_t, destroy_task); + xnselect->handler (xnselect->arg); +} + +int cobalt_select_init (cobalt_select_work_t *xnselect, +cobalt_select_destroy_t handler,void *arg) +{ + xnselect->handler = handler; + xnselect->arg = arg; +INIT_WORK (&xnselect->destroy_task, cobalt_select_execute); +return 0 ; +} +/** * @ingroup cobalt_core @@ -49,7 +117,6 @@*/ static LIST_HEAD (selector_list); -static int deletion_apc;/** * Initialize a @a struct @a xnselect structure. @@ -399,9 +466,10 @@ void xnselector_destroy(struct xnselector *selector)xnlock_get_irqsave (&nklock, s);list_add_tail (&selector->destroy_link, &selector_list); -#warning TODO: irq_work -//__xnapc_schedule(deletion_apc); xnlock_put_irqrestore (&nklock, s); +if (cobalt_select_isinit == true) +xnselect_schedule_work (&xndeletion_work.destroy_task); + }EXPORT_SYMBOL_GPL (xnselector_destroy);@@ -444,18 +512,20 @@ out:int xnselect_mount (void ) { -#warning TODO: use irq_work -/*deletion_apc = xnapc_alloc("selector_list_destroy", -xnselector_destroy_loop, NULL); -if (deletion_apc < 0) -return deletion_apc;*/ +int ret; -return 0 ; + cobalt_select_isinit = false; + + ret =cobalt_select_init (&xndeletion_work, xnselector_destroy_loop,NULL ); +if (!ret) + cobalt_select_isinit = true; +return ret;
kernel/cobalt/select.c out: · line 531
Quoted 10 lines
kernel/cobalt/select.c +2
-1}int xnselect_umount (void ) { -//xnapc_free(deletion_apc); + cobalt_select_isinit = false; +cancel_work_sync (&xndeletion_work.destroy_task);return 0 ; }
OK, so this replaced v2 sent to the list?
Please stay on the list with the patches, maybe just mark them additionally with "[dovetail]" or so.
Jan
PS: Sorry, I'm late with replying.
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Quoted 12 lines · On 24.09.20 08:54, hongzha1 wrote:
Quoted 11 lines
schedule
irq_workwhich is to schedule work to execute heavyxnselector_destroy_loopinstead of calling__xnapc_schedule.Signed-off-by hongzha1 <[email protected]>---
this patch is for wip/dovetail. This is new version. It would scheduleirq_workwhich is to schedule work to execute heavyxnselector_destroy_loopbut not execute it inirq_workdirectly instead of calling__xnapc_schedule.
Quoted 5 lines
What is the benefit of this indirection to a workqueue?
irq_work- as hardened by dovetail for triggering from oob / xenomai context - still run the work in in-band / Linux context, just in an interrupt. IIRC, that is the same with the previous APC mechanism, so a 1:1 match.
Hi Jan,
My purpose is to keep running short in interrupt context and do the main work later in work thread in linux. In this case, schedule_work running in irq_work would be very short but at least shorter than running xnselector_destroy_loop directly. In addition, xnselector_destroy_loop seems doing lots of things including xnsynch_destroy and xnfree involving page remove and xnsched_run in a loop. That is why I try to make it run in work thread.
Quoted 135 lines
Quoted 82 lines
kernel/cobalt/select.c +69
-1@@ -23,7 +23,75 @@#include <cobalt/kernel/sched.h> #include <cobalt/kernel/synch.h> #include <cobalt/kernel/select.h> -#include <cobalt/kernel/apc.h> +#include <linux/irq_work.h> + +static bool cobalt_select_isinit; +static LIST_HEAD (xnselect_work_queue); + +typedef void (*cobalt_select_destroy_t ) (void *cookie); + +struct cobalt_select_work { +cobalt_select_destroy_t handler; +void *arg; +struct work_struct destroy_task; +}; + +typedef struct cobalt_select_work cobalt_select_work_t ; + +static cobalt_select_work_t xndeletion_work; + +static void do_xnselect_work (struct irq_work *work) +{ +struct work_struct *xnselect_work; +spl_t s; + +xnlock_get_irqsave (&nklock, s); +while (!list_empty (&xnselect_work_queue)) { + xnselect_work =list_first_entry (&xnselect_work_queue, + struct work_struct, entry); +list_del_init (&xnselect_work->entry); +xnlock_put_irqrestore (&nklock, s); + +schedule_work (xnselect_work); + +xnlock_get_irqsave (&nklock, s); + + } +xnlock_put_irqrestore (&nklock, s); + +} + +static DEFINE_IRQ_WORK(xnselect_irq_work, do_xnselect_work); + +typedef void (*cobalt_select_destroy_t )(void *cookie); + +void xnselect_schedule_work (struct work_struct *destroy_work) +{ +spl_t s; + +xnlock_get_irqsave (&nklock, s); +list_add_tail (&xnselect_work_queue, &destroy_work->entry); +xnlock_put_irqrestore (&nklock, s); + +irq_work_queue (&xnselect_irq_work); +} + +static void cobalt_select_execute (struct work_struct *work) +{ +cobalt_select_work_t *xnselect = +container_of (work, cobalt_select_work_t, destroy_task); + xnselect->handler (xnselect->arg); +} + +int cobalt_select_init (cobalt_select_work_t *xnselect, +cobalt_select_destroy_t handler,void *arg) +{ + xnselect->handler = handler; + xnselect->arg = arg; +INIT_WORK (&xnselect->destroy_task, cobalt_select_execute); +return 0 ; +} +/** * @ingroup cobalt_core (quoted diff) +0
-0@@ -49,7 +117,6 @@Quoted 39 lines
*/
static
LIST_HEAD(selector_list);kernel/cobalt/select.c +10
-9-static int deletion_apc;/** * Initialize a @a struct @a xnselect structure. @@ -399,9 +466,10 @@ void xnselector_destroy(struct xnselector *selector)xnlock_get_irqsave (&nklock, s);list_add_tail (&selector->destroy_link, &selector_list); -#warning TODO: irq_work -//__xnapc_schedule(deletion_apc); xnlock_put_irqrestore (&nklock, s); +if (cobalt_select_isinit == true) +xnselect_schedule_work (&xndeletion_work.destroy_task); + }EXPORT_SYMBOL_GPL (xnselector_destroy);@@ -444,18 +512,20 @@ out:int xnselect_mount (void ) { -#warning TODO: use irq_work -/*deletion_apc = xnapc_alloc("selector_list_destroy", -xnselector_destroy_loop, NULL); -if (deletion_apc < 0) -return deletion_apc;*/ +int ret; -return 0 ; + cobalt_select_isinit = false; + + ret =cobalt_select_init (&xndeletion_work, xnselector_destroy_loop,NULL ); +if (!ret) + cobalt_select_isinit = true; +return ret;kernel/cobalt/select.c out: · line 531
Quoted 10 lines
kernel/cobalt/select.c +2
-1}int xnselect_umount (void ) { -//xnapc_free(deletion_apc); + cobalt_select_isinit = false; +cancel_work_sync (&xndeletion_work.destroy_task);return 0 ; }OK, so this replaced v2 sent to the list?
Quoted 2 lines
Please stay on the list with the patches, maybe just mark them additionally with "[dovetail]" or so.
OK. Sorry for the inconvenience.
Quoted 5 lines
Jan
PS: Sorry, I'm late with replying.
Regards
Hongzhan Chen
PATCH v2 1/1 cobalt/select: replace APC with irq_work
In reply to Jan Kiszkaschedule irq_work to execute xnselector_destroy_loop instead of calling __xnapc_schedule, which is to replace APC
kernel/cobalt/select.c +14 -11
@@ -23,7 +23,12 @@#include <cobalt/kernel/sched.h> #include <cobalt/kernel/synch.h> #include <cobalt/kernel/select.h> -#include <cobalt/kernel/apc.h> +#include <linux/irq_work.h> + + +static void cobalt_select_execute (struct irq_work *work); + +static DEFINE_IRQ_WORK(xnselect_irq_work, cobalt_select_execute);/** * @ingroup cobalt_core
@@ -49,7 +54,6 @@*/ static LIST_HEAD (selector_list); -static int deletion_apc;/** * Initialize a @a struct @a xnselect structure.
@@ -399,9 +403,9 @@ void xnselector_destroy(struct xnselector *selector)xnlock_get_irqsave (&nklock, s);list_add_tail (&selector->destroy_link, &selector_list); -#warning TODO: irq_work -//__xnapc_schedule(deletion_apc); xnlock_put_irqrestore (&nklock, s); + +irq_work_queue (&xnselect_irq_work); }EXPORT_SYMBOL_GPL (xnselector_destroy);
@@ -442,20 +446,19 @@ out:xnlock_put_irqrestore (&nklock, s); } -int xnselect_mount (void ) +static void cobalt_select_execute (struct irq_work *work) { -#warning TODO: use irq_work -/*deletion_apc = xnapc_alloc("selector_list_destroy", -xnselector_destroy_loop, NULL); -if (deletion_apc < 0) -return deletion_apc;*/ +xnselector_destroy_loop (NULL ); +} + +int xnselect_mount (void ) +{return 0 ; }int xnselect_umount (void ) { -//xnapc_free(deletion_apc); return 0 ; }
Signature · 1 line
2.17.1
Quoted 61 lines · On 30.09.20 05:00, hongzha1 wrote:
schedule
irq_workto executexnselector_destroy_loopinstead of calling__xnapc_schedule, which is to replace APCSigned-off-by hongzha1 <[email protected]>kernel/cobalt/select.c +13
-10@@ -23,7 +23,12 @@#include <cobalt/kernel/sched.h> #include <cobalt/kernel/synch.h> #include <cobalt/kernel/select.h> -#include <cobalt/kernel/apc.h> +#include <linux/irq_work.h> + + +static void cobalt_select_execute (struct irq_work *work); + +static DEFINE_IRQ_WORK(xnselect_irq_work, cobalt_select_execute);/** * @ingroup cobalt_core @@ -49,7 +54,6 @@*/ static LIST_HEAD (selector_list); -static int deletion_apc;/** * Initialize a @a struct @a xnselect structure. @@ -399,9 +403,9 @@ void xnselector_destroy(struct xnselector *selector)xnlock_get_irqsave (&nklock, s);list_add_tail (&selector->destroy_link, &selector_list); -#warning TODO: irq_work -//__xnapc_schedule(deletion_apc); xnlock_put_irqrestore (&nklock, s); + +irq_work_queue (&xnselect_irq_work); }EXPORT_SYMBOL_GPL (xnselector_destroy);@@ -442,20 +446,19 @@ out:xnlock_put_irqrestore (&nklock, s); } -int xnselect_mount (void ) +static void cobalt_select_execute (struct irq_work *work) { -#warning TODO: use irq_work -/*deletion_apc = xnapc_alloc("selector_list_destroy", -xnselector_destroy_loop, NULL); -if (deletion_apc < 0) -return deletion_apc;*/ +xnselector_destroy_loop (NULL ); +} + +int xnselect_mount (void )
kernel/cobalt/select.c out: · line 464
Quoted 10 lines
kernel/cobalt/select.c +1
-1+{return 0 ; }int xnselect_umount (void ) { -//xnapc_free(deletion_apc); return 0 ; }
Thanks, merged.
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux