All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] [PATCH] cobalt/sched: group high-level init/cleanup code
@ 2018-09-04 10:54 Philippe Gerum
  2018-09-04 17:30 ` Jan Kiszka
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Gerum @ 2018-09-04 10:54 UTC (permalink / raw)
  To: xenomai

Move scheduler init/cleanup bits to dedicated routines.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 include/cobalt/kernel/sched.h |  4 ++--
 kernel/cobalt/init.c          | 41 +++-------------------------------
 kernel/cobalt/sched.c         | 51 +++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 54 insertions(+), 42 deletions(-)

diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index d525fb2cb..03436ee82 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -381,9 +381,9 @@ void xnsched_cleanup_proc(void);
 
 void xnsched_register_classes(void);
 
-void xnsched_init(struct xnsched *sched, int cpu);
+void xnsched_init_all(void);
 
-void xnsched_destroy(struct xnsched *sched);
+void xnsched_destroy_all(void);
 
 struct xnthread *xnsched_pick_next(struct xnsched *sched);
 
diff --git a/kernel/cobalt/init.c b/kernel/cobalt/init.c
index bdd9f351b..22066953b 100644
--- a/kernel/cobalt/init.c
+++ b/kernel/cobalt/init.c
@@ -124,34 +124,10 @@ EXPORT_SYMBOL_GPL(cobalt_call_state_chain);
 
 static void sys_shutdown(void)
 {
-	struct xnthread *thread, *tmp;
-	struct xnsched *sched;
 	void *membase;
-	int cpu;
-	spl_t s;
 
 	xntimer_release_hardware();
-#ifdef CONFIG_SMP
-	ipipe_free_irq(&xnsched_realtime_domain, IPIPE_RESCHEDULE_IPI);
-#endif
-
-	xnlock_get_irqsave(&nklock, s);
-
-	/* NOTE: &nkthreadq can't be empty (root thread(s)). */
-	list_for_each_entry_safe(thread, tmp, &nkthreadq, glink) {
-		if (!xnthread_test_state(thread, XNROOT))
-			xnthread_cancel(thread);
-	}
-
-	xnsched_run();
-
-	for_each_online_cpu(cpu) {
-		sched = xnsched_struct(cpu);
-		xnsched_destroy(sched);
-	}
-
-	xnlock_put_irqrestore(&nklock, s);
-
+	xnsched_destroy_all();
 	xnregistry_cleanup();
 	membase = xnheap_get_membase(&cobalt_heap);
 	xnheap_destroy(&cobalt_heap);
@@ -281,9 +257,8 @@ static void __init setup_init_state(void)
 
 static __init int sys_init(void)
 {
-	struct xnsched *sched;
 	void *heapaddr;
-	int ret, cpu;
+	int ret;
 
 	if (sysheap_size_arg == 0)
 		sysheap_size_arg = CONFIG_XENO_OPT_SYS_HEAPSZ;
@@ -295,17 +270,7 @@ static __init int sys_init(void)
 	}
 	xnheap_set_name(&cobalt_heap, "system heap");
 
-	for_each_online_cpu(cpu) {
-		sched = &per_cpu(nksched, cpu);
-		xnsched_init(sched, cpu);
-	}
-
-#ifdef CONFIG_SMP
-	ipipe_request_irq(&xnsched_realtime_domain,
-			  IPIPE_RESCHEDULE_IPI,
-			  (ipipe_irq_handler_t)__xnsched_run_handler,
-			  NULL, NULL);
-#endif
+	xnsched_init_all();
 
 	xnregistry_init();
 
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index db7bb11f1..76e3bc5d7 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -149,7 +149,7 @@ static void roundrobin_handler(struct xntimer *timer)
 	xnsched_tick(sched);
 }
 
-void xnsched_init(struct xnsched *sched, int cpu)
+static void xnsched_init(struct xnsched *sched, int cpu)
 {
 	char rrbtimer_name[XNOBJECT_NAME_LEN];
 	char htimer_name[XNOBJECT_NAME_LEN];
@@ -219,7 +219,25 @@ void xnsched_init(struct xnsched *sched, int cpu)
 #endif /* CONFIG_XENO_OPT_WATCHDOG */
 }
 
-void xnsched_destroy(struct xnsched *sched)
+void xnsched_init_all(void)
+{
+	struct xnsched *sched;
+	int cpu;
+
+	for_each_online_cpu(cpu) {
+		sched = &per_cpu(nksched, cpu);
+		xnsched_init(sched, cpu);
+	}
+
+#ifdef CONFIG_SMP
+	ipipe_request_irq(&xnsched_realtime_domain,
+			  IPIPE_RESCHEDULE_IPI,
+			  (ipipe_irq_handler_t)__xnsched_run_handler,
+			  NULL, NULL);
+#endif
+}
+
+static void xnsched_destroy(struct xnsched *sched)
 {
 	xntimer_destroy(&sched->htimer);
 	xntimer_destroy(&sched->rrbtimer);
@@ -230,6 +248,35 @@ void xnsched_destroy(struct xnsched *sched)
 #endif /* CONFIG_XENO_OPT_WATCHDOG */
 }
 
+void xnsched_destroy_all(void)
+{
+	struct xnthread *thread, *tmp;
+	struct xnsched *sched;
+	int cpu;
+	spl_t s;
+
+#ifdef CONFIG_SMP
+	ipipe_free_irq(&xnsched_realtime_domain, IPIPE_RESCHEDULE_IPI);
+#endif
+
+	xnlock_get_irqsave(&nklock, s);
+
+	/* NOTE: &nkthreadq can't be empty (root thread(s)). */
+	list_for_each_entry_safe(thread, tmp, &nkthreadq, glink) {
+		if (!xnthread_test_state(thread, XNROOT))
+			xnthread_cancel(thread);
+	}
+
+	xnsched_run();
+
+	for_each_online_cpu(cpu) {
+		sched = xnsched_struct(cpu);
+		xnsched_destroy(sched);
+	}
+
+	xnlock_put_irqrestore(&nklock, s);
+}
+
 static inline void set_thread_running(struct xnsched *sched,
 				      struct xnthread *thread)
 {
-- 
2.14.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Xenomai] [PATCH] cobalt/sched: group high-level init/cleanup code
  2018-09-04 10:54 [Xenomai] [PATCH] cobalt/sched: group high-level init/cleanup code Philippe Gerum
@ 2018-09-04 17:30 ` Jan Kiszka
  2018-09-05  7:41   ` Philippe Gerum
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2018-09-04 17:30 UTC (permalink / raw)
  To: Philippe Gerum, xenomai

On 2018-09-04 12:54, Philippe Gerum wrote:
> Move scheduler init/cleanup bits to dedicated routines.
> 

Looks good. I assume the underlying motivation is something like this:
"This concentrates scheduler related code in the sched module."
(I will insist on such reasoning for more complex code ;) ).

Thanks,
Jan

> Signed-off-by: Philippe Gerum <rpm@xenomai.org>
> ---
>   include/cobalt/kernel/sched.h |  4 ++--
>   kernel/cobalt/init.c          | 41 +++-------------------------------
>   kernel/cobalt/sched.c         | 51 +++++++++++++++++++++++++++++++++++++++++--
>   3 files changed, 54 insertions(+), 42 deletions(-)
> 
> diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
> index d525fb2cb..03436ee82 100644
> --- a/include/cobalt/kernel/sched.h
> +++ b/include/cobalt/kernel/sched.h
> @@ -381,9 +381,9 @@ void xnsched_cleanup_proc(void);
>   
>   void xnsched_register_classes(void);
>   
> -void xnsched_init(struct xnsched *sched, int cpu);
> +void xnsched_init_all(void);
>   
> -void xnsched_destroy(struct xnsched *sched);
> +void xnsched_destroy_all(void);
>   
>   struct xnthread *xnsched_pick_next(struct xnsched *sched);
>   
> diff --git a/kernel/cobalt/init.c b/kernel/cobalt/init.c
> index bdd9f351b..22066953b 100644
> --- a/kernel/cobalt/init.c
> +++ b/kernel/cobalt/init.c
> @@ -124,34 +124,10 @@ EXPORT_SYMBOL_GPL(cobalt_call_state_chain);
>   
>   static void sys_shutdown(void)
>   {
> -	struct xnthread *thread, *tmp;
> -	struct xnsched *sched;
>   	void *membase;
> -	int cpu;
> -	spl_t s;
>   
>   	xntimer_release_hardware();
> -#ifdef CONFIG_SMP
> -	ipipe_free_irq(&xnsched_realtime_domain, IPIPE_RESCHEDULE_IPI);
> -#endif
> -
> -	xnlock_get_irqsave(&nklock, s);
> -
> -	/* NOTE: &nkthreadq can't be empty (root thread(s)). */
> -	list_for_each_entry_safe(thread, tmp, &nkthreadq, glink) {
> -		if (!xnthread_test_state(thread, XNROOT))
> -			xnthread_cancel(thread);
> -	}
> -
> -	xnsched_run();
> -
> -	for_each_online_cpu(cpu) {
> -		sched = xnsched_struct(cpu);
> -		xnsched_destroy(sched);
> -	}
> -
> -	xnlock_put_irqrestore(&nklock, s);
> -
> +	xnsched_destroy_all();
>   	xnregistry_cleanup();
>   	membase = xnheap_get_membase(&cobalt_heap);
>   	xnheap_destroy(&cobalt_heap);
> @@ -281,9 +257,8 @@ static void __init setup_init_state(void)
>   
>   static __init int sys_init(void)
>   {
> -	struct xnsched *sched;
>   	void *heapaddr;
> -	int ret, cpu;
> +	int ret;
>   
>   	if (sysheap_size_arg == 0)
>   		sysheap_size_arg = CONFIG_XENO_OPT_SYS_HEAPSZ;
> @@ -295,17 +270,7 @@ static __init int sys_init(void)
>   	}
>   	xnheap_set_name(&cobalt_heap, "system heap");
>   
> -	for_each_online_cpu(cpu) {
> -		sched = &per_cpu(nksched, cpu);
> -		xnsched_init(sched, cpu);
> -	}
> -
> -#ifdef CONFIG_SMP
> -	ipipe_request_irq(&xnsched_realtime_domain,
> -			  IPIPE_RESCHEDULE_IPI,
> -			  (ipipe_irq_handler_t)__xnsched_run_handler,
> -			  NULL, NULL);
> -#endif
> +	xnsched_init_all();
>   
>   	xnregistry_init();
>   
> diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
> index db7bb11f1..76e3bc5d7 100644
> --- a/kernel/cobalt/sched.c
> +++ b/kernel/cobalt/sched.c
> @@ -149,7 +149,7 @@ static void roundrobin_handler(struct xntimer *timer)
>   	xnsched_tick(sched);
>   }
>   
> -void xnsched_init(struct xnsched *sched, int cpu)
> +static void xnsched_init(struct xnsched *sched, int cpu)
>   {
>   	char rrbtimer_name[XNOBJECT_NAME_LEN];
>   	char htimer_name[XNOBJECT_NAME_LEN];
> @@ -219,7 +219,25 @@ void xnsched_init(struct xnsched *sched, int cpu)
>   #endif /* CONFIG_XENO_OPT_WATCHDOG */
>   }
>   
> -void xnsched_destroy(struct xnsched *sched)
> +void xnsched_init_all(void)
> +{
> +	struct xnsched *sched;
> +	int cpu;
> +
> +	for_each_online_cpu(cpu) {
> +		sched = &per_cpu(nksched, cpu);
> +		xnsched_init(sched, cpu);
> +	}
> +
> +#ifdef CONFIG_SMP
> +	ipipe_request_irq(&xnsched_realtime_domain,
> +			  IPIPE_RESCHEDULE_IPI,
> +			  (ipipe_irq_handler_t)__xnsched_run_handler,
> +			  NULL, NULL);
> +#endif
> +}
> +
> +static void xnsched_destroy(struct xnsched *sched)
>   {
>   	xntimer_destroy(&sched->htimer);
>   	xntimer_destroy(&sched->rrbtimer);
> @@ -230,6 +248,35 @@ void xnsched_destroy(struct xnsched *sched)
>   #endif /* CONFIG_XENO_OPT_WATCHDOG */
>   }
>   
> +void xnsched_destroy_all(void)
> +{
> +	struct xnthread *thread, *tmp;
> +	struct xnsched *sched;
> +	int cpu;
> +	spl_t s;
> +
> +#ifdef CONFIG_SMP
> +	ipipe_free_irq(&xnsched_realtime_domain, IPIPE_RESCHEDULE_IPI);
> +#endif
> +
> +	xnlock_get_irqsave(&nklock, s);
> +
> +	/* NOTE: &nkthreadq can't be empty (root thread(s)). */
> +	list_for_each_entry_safe(thread, tmp, &nkthreadq, glink) {
> +		if (!xnthread_test_state(thread, XNROOT))
> +			xnthread_cancel(thread);
> +	}
> +
> +	xnsched_run();
> +
> +	for_each_online_cpu(cpu) {
> +		sched = xnsched_struct(cpu);
> +		xnsched_destroy(sched);
> +	}
> +
> +	xnlock_put_irqrestore(&nklock, s);
> +}
> +
>   static inline void set_thread_running(struct xnsched *sched,
>   				      struct xnthread *thread)
>   {
> 

-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai] [PATCH] cobalt/sched: group high-level init/cleanup code
  2018-09-04 17:30 ` Jan Kiszka
@ 2018-09-05  7:41   ` Philippe Gerum
  0 siblings, 0 replies; 3+ messages in thread
From: Philippe Gerum @ 2018-09-05  7:41 UTC (permalink / raw)
  To: Jan Kiszka, xenomai

On 09/04/2018 07:30 PM, Jan Kiszka wrote:
> On 2018-09-04 12:54, Philippe Gerum wrote:
>> Move scheduler init/cleanup bits to dedicated routines.
>>
> 
> Looks good. I assume the underlying motivation is something like this:
> "This concentrates scheduler related code in the sched module."
> (I will insist on such reasoning for more complex code ;) ).
> 

Yes, we may also need global sched-specific inits in the future which
might not be per-cpu related.

-- 
Philippe.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-09-05  7:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-04 10:54 [Xenomai] [PATCH] cobalt/sched: group high-level init/cleanup code Philippe Gerum
2018-09-04 17:30 ` Jan Kiszka
2018-09-05  7:41   ` Philippe Gerum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.