All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels
@ 2012-12-21 13:26 Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 01/10] ipipe: Add root domain guard to preempt_schedule Wolfgang Mauerer
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

Hi Gilles, Jan,

here's a proposal to make ipipe compatible with ftrace that
does not require global modifications to the preemption system,
but makes do with local changes. The approach should be easy
to maintain in the long run:

- ipipe_safe_preempt_xyz() counterparts for the preemption API
  need to be provided.
- Portions of the kernel that need to call into the preemption API
  from non-root context must ensure that they #include the new
  linux/ipipe_switch_preempt.h header file.

All callers of the preempt API that are not converted continue to
trigger an ipipe panic as before if they are called from non-root
context, which is an advantage compared to approaches that
change the preemption API globally. Almost all changes are to
ipipe-specific files, which should also ease maintainability.

NOTE: The series has only been tested _very_ superficially.
Before I spend more effort, I'd like to have some feedback if
you see any fundamental issues with the approach.

The changes are also on github, see below.

Best regards, Wolfgang

---
The following changes since commit 4b451bb6508b3a2f27b6d0e5c1d813f4f109abdb:

  Fix dispatching of IRQ_MOVE_CLEANUP_VECTOR (2012-10-08 14:57:53 +0200)

are available in the git repository at:
  https://github.com/siemens/ipipe.git ftrace

Jan Kiszka (4):
      ipipe: Add root domain guard to preempt_schedule
      ipipe: Harden clocks used by ftrace and perf
      ipipe: Harden ftrace function and function-graph tracer
      Harden trace_vbprintk for non-root use

Wolfgang Mauerer (6):
      ipipe: Remove superfluous include file in ipipe.h
      ipipe: safe thread_info access from non-root context
      ipipe: Add mechanism to allow preemption calls from non-root context
      ipipe: Introduce preemption call replacement mechanism
      ipipe: Fix CONFIG_PREEMPT build
      ipipe: Make ftrace compatible with ipipe

 include/linux/ipipe.h                |   33 +---------------
 include/linux/ipipe_foreign_stack.h  |   70 ++++++++++++++++++++++++++++++++++
 include/linux/ipipe_switch_preempt.h |   31 +++++++++++++++
 kernel/ipipe/core.c                  |   52 +++++++++++++++++++++++++
 kernel/sched/clock.c                 |    6 ++-
 kernel/sched/core.c                  |    3 +-
 kernel/trace/trace.c                 |    6 +-
 kernel/trace/trace.h                 |    1 +
 kernel/trace/trace_clock.c           |    4 +-
 kernel/trace/trace_functions.c       |    8 ++--
 kernel/trace/trace_functions_graph.c |    8 ++--
 11 files changed, 174 insertions(+), 48 deletions(-)
 create mode 100644 include/linux/ipipe_foreign_stack.h
 create mode 100644 include/linux/ipipe_switch_preempt.h

--
Siemens AG, Corporate Technology
Corporate Competence Centre Embedded Linux


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

* [Xenomai] [PATCH 01/10] ipipe: Add root domain guard to preempt_schedule
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
@ 2012-12-21 13:26 ` Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 02/10] ipipe: Harden clocks used by ftrace and perf Wolfgang Mauerer
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

From: Jan Kiszka <jan.kiszka@siemens.com>

When we start allowing preempt_disable/enable over non-root domains,
there is the risk to re-enable preemption in non-root contexts. If also
TIF_NEED_RESCHED is set, this will result in a call to preempt_schedule.
Therefore we have to catch any rescheduling over non-root domains on
preempt_schedule entry.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
---
 kernel/sched/core.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ec38567..9fdcc22 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3557,7 +3557,8 @@ asmlinkage void __sched notrace preempt_schedule(void)
 	 * If there is a non-zero preempt_count or interrupts are disabled,
 	 * we do not want to preempt the current task. Just return..
 	 */
-	if (likely(ti->preempt_count || irqs_disabled()))
+	if (likely(ti->preempt_count || irqs_disabled() ||
+		   !ipipe_root_domain_p))
 		return;
 
 	do {
-- 
1.7.1



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

* [Xenomai] [PATCH 02/10] ipipe: Harden clocks used by ftrace and perf
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 01/10] ipipe: Add root domain guard to preempt_schedule Wolfgang Mauerer
@ 2012-12-21 13:26 ` Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 03/10] ipipe: Harden ftrace function and function-graph tracer Wolfgang Mauerer
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

From: Jan Kiszka <jan.kiszka@siemens.com>

Convert local_irq_save/restore into hw variates in those cpu/sched_clock
paths that are used by ftrace and perf. We don't want to trace them to
reduce the overhead.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
---
 kernel/sched/clock.c       |    6 ++++--
 kernel/trace/trace_clock.c |    4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c
index c685e31..67cad6f 100644
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -216,7 +216,9 @@ u64 sched_clock_cpu(int cpu)
 	struct sched_clock_data *scd;
 	u64 clock;
 
+#ifndef CONFIG_IPIPE
 	WARN_ON_ONCE(!irqs_disabled());
+#endif
 
 	if (sched_clock_stable)
 		return sched_clock();
@@ -293,9 +295,9 @@ u64 cpu_clock(int cpu)
 	u64 clock;
 	unsigned long flags;
 
-	local_irq_save(flags);
+	flags = hard_local_irq_save_notrace();
 	clock = sched_clock_cpu(cpu);
-	local_irq_restore(flags);
+	hard_local_irq_restore_notrace(flags);
 
 	return clock;
 }
diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
index 3947835..4e297ad 100644
--- a/kernel/trace/trace_clock.c
+++ b/kernel/trace/trace_clock.c
@@ -83,7 +83,7 @@ u64 notrace trace_clock_global(void)
 	int this_cpu;
 	u64 now;
 
-	local_irq_save(flags);
+	flags = hard_local_irq_save_notrace();
 
 	this_cpu = raw_smp_processor_id();
 	now = cpu_clock(this_cpu);
@@ -109,7 +109,7 @@ u64 notrace trace_clock_global(void)
 	arch_spin_unlock(&trace_clock_struct.lock);
 
  out:
-	local_irq_restore(flags);
+	hard_local_irq_restore_notrace(flags);
 
 	return now;
 }
-- 
1.7.1



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

* [Xenomai] [PATCH 03/10] ipipe: Harden ftrace function and function-graph tracer
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 01/10] ipipe: Add root domain guard to preempt_schedule Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 02/10] ipipe: Harden clocks used by ftrace and perf Wolfgang Mauerer
@ 2012-12-21 13:26 ` Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 04/10] Harden trace_vbprintk for non-root use Wolfgang Mauerer
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

From: Jan Kiszka <jan.kiszka@siemens.com>

Again no tracing of local_irq_disable/enable_hw for the sake of reduced
overhead.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
---
 kernel/trace/trace_functions.c       |    8 ++++----
 kernel/trace/trace_functions_graph.c |    8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index c7b0c6a..bdf3c8f 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -91,7 +91,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip)
 	 * Need to use raw, since this must be called before the
 	 * recursive protection is performed.
 	 */
-	local_irq_save(flags);
+	flags = hard_local_irq_save();
 	cpu = raw_smp_processor_id();
 	data = tr->data[cpu];
 	disabled = atomic_inc_return(&data->disabled);
@@ -102,7 +102,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip)
 	}
 
 	atomic_dec(&data->disabled);
-	local_irq_restore(flags);
+	hard_local_irq_restore(flags);
 }
 
 static void
@@ -122,7 +122,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip)
 	 * Need to use raw, since this must be called before the
 	 * recursive protection is performed.
 	 */
-	local_irq_save(flags);
+	flags = hard_local_irq_save();
 	cpu = raw_smp_processor_id();
 	data = tr->data[cpu];
 	disabled = atomic_inc_return(&data->disabled);
@@ -142,7 +142,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip)
 	}
 
 	atomic_dec(&data->disabled);
-	local_irq_restore(flags);
+	hard_local_irq_restore(flags);
 }
 
 
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index a7d2a4c..c8e214b 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -251,7 +251,7 @@ int trace_graph_entry(struct ftrace_graph_ent *trace)
 	      ftrace_graph_ignore_irqs())
 		return 0;
 
-	local_irq_save(flags);
+	flags = hard_local_irq_save_notrace();
 	cpu = raw_smp_processor_id();
 	data = tr->data[cpu];
 	disabled = atomic_inc_return(&data->disabled);
@@ -263,7 +263,7 @@ int trace_graph_entry(struct ftrace_graph_ent *trace)
 	}
 
 	atomic_dec(&data->disabled);
-	local_irq_restore(flags);
+	hard_local_irq_restore_notrace(flags);
 
 	return ret;
 }
@@ -336,7 +336,7 @@ void trace_graph_return(struct ftrace_graph_ret *trace)
 	int cpu;
 	int pc;
 
-	local_irq_save(flags);
+	flags = hard_local_irq_save_notrace();
 	cpu = raw_smp_processor_id();
 	data = tr->data[cpu];
 	disabled = atomic_inc_return(&data->disabled);
@@ -345,7 +345,7 @@ void trace_graph_return(struct ftrace_graph_ret *trace)
 		__trace_graph_return(tr, trace, flags, pc);
 	}
 	atomic_dec(&data->disabled);
-	local_irq_restore(flags);
+	hard_local_irq_restore_notrace(flags);
 }
 
 void set_graph_array(struct trace_array *tr)
-- 
1.7.1



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

* [Xenomai] [PATCH 04/10] Harden trace_vbprintk for non-root use
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
                   ` (2 preceding siblings ...)
  2012-12-21 13:26 ` [Xenomai] [PATCH 03/10] ipipe: Harden ftrace function and function-graph tracer Wolfgang Mauerer
@ 2012-12-21 13:26 ` Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 05/10] ipipe: Remove superfluous include file in ipipe.h Wolfgang Mauerer
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

From: Jan Kiszka <jan.kiszka@siemens.com>

We depend on hard-irqs being disabled to push trace_printk
data safely to ftrace.

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 kernel/trace/trace.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a7fa070..a85936f 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1592,8 +1592,9 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
 	/* Don't pollute graph traces with trace_vprintk internals */
 	pause_graph_tracing();
 
+	flags = hard_local_irq_save();
+
 	pc = preempt_count();
-	preempt_disable_notrace();
 
 	tbuffer = get_trace_buf();
 	if (!tbuffer) {
@@ -1606,7 +1607,6 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
 	if (len > TRACE_BUF_SIZE/sizeof(int) || len < 0)
 		goto out;
 
-	local_save_flags(flags);
 	size = sizeof(*entry) + sizeof(u32) * len;
 	buffer = tr->buffer;
 	event = trace_buffer_lock_reserve(buffer, TRACE_BPRINT, size,
@@ -1624,7 +1624,7 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
 	}
 
 out:
-	preempt_enable_notrace();
+	hard_local_irq_restore(flags);
 	unpause_graph_tracing();
 
 	return len;
-- 
1.7.1



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

* [Xenomai] [PATCH 05/10] ipipe: Remove superfluous include file in ipipe.h
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
                   ` (3 preceding siblings ...)
  2012-12-21 13:26 ` [Xenomai] [PATCH 04/10] Harden trace_vbprintk for non-root use Wolfgang Mauerer
@ 2012-12-21 13:26 ` Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 06/10] ipipe: safe thread_info access from non-root context Wolfgang Mauerer
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
---
 include/linux/ipipe.h |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/include/linux/ipipe.h b/include/linux/ipipe.h
index 11fc093..bcd5d41 100644
--- a/include/linux/ipipe.h
+++ b/include/linux/ipipe.h
@@ -22,7 +22,6 @@
 #ifndef __LINUX_IPIPE_H
 #define __LINUX_IPIPE_H
 
-#include <linux/spinlock.h>
 #include <linux/cache.h>
 #include <linux/percpu.h>
 #include <linux/irq.h>
-- 
1.7.1



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

* [Xenomai] [PATCH 06/10] ipipe: safe thread_info access from non-root context
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
                   ` (4 preceding siblings ...)
  2012-12-21 13:26 ` [Xenomai] [PATCH 05/10] ipipe: Remove superfluous include file in ipipe.h Wolfgang Mauerer
@ 2012-12-21 13:26 ` Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 07/10] ipipe: Add mechanism to allow preemption calls " Wolfgang Mauerer
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

Provide a function that allows for safely accessing
the thread_info structure from non-root context.
Architectures that don't store the corresponding
data on the stack (x86_64) can provide machine-specific
override definitions. Also create a own header file
(including the other definitions to access foreign stacks)
so that the mechanism can be used in contexts where not
the full ipipe API is required.

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
---
 include/linux/ipipe.h               |   32 +------------------
 include/linux/ipipe_foreign_stack.h |   61 +++++++++++++++++++++++++++++++++++
 kernel/ipipe/core.c                 |    1 +
 3 files changed, 63 insertions(+), 31 deletions(-)
 create mode 100644 include/linux/ipipe_foreign_stack.h

diff --git a/include/linux/ipipe.h b/include/linux/ipipe.h
index bcd5d41..6f011cc 100644
--- a/include/linux/ipipe.h
+++ b/include/linux/ipipe.h
@@ -27,6 +27,7 @@
 #include <linux/irq.h>
 #include <linux/thread_info.h>
 #include <linux/ipipe_base.h>
+#include <linux/ipipe_foreign_stack.h>
 #include <linux/ipipe_debug.h>
 #include <asm/ptrace.h>
 #include <asm/ipipe.h>
@@ -226,36 +227,6 @@ void ipipe_critical_exit(unsigned long flags);
 
 void ipipe_prepare_panic(void);
 
-static inline void ipipe_set_foreign_stack(struct ipipe_domain *ipd)
-{
-	/* Must be called hw interrupts off. */
-	__set_bit(IPIPE_NOSTACK_FLAG, &ipipe_this_cpu_context(ipd)->status);
-}
-
-static inline void ipipe_clear_foreign_stack(struct ipipe_domain *ipd)
-{
-	/* Must be called hw interrupts off. */
-	__clear_bit(IPIPE_NOSTACK_FLAG, &ipipe_this_cpu_context(ipd)->status);
-}
-
-static inline int ipipe_test_foreign_stack(void)
-{
-	/* Must be called hw interrupts off. */
-	return test_bit(IPIPE_NOSTACK_FLAG, &__ipipe_current_context->status);
-}
-
-#ifndef ipipe_safe_current
-#define ipipe_safe_current()						\
-	({								\
-		struct task_struct *__p__;				\
-		unsigned long __flags__;				\
-		__flags__ = hard_smp_local_irq_save();			\
-		__p__ = ipipe_test_foreign_stack() ? &init_task : current; \
-		hard_smp_local_irq_restore(__flags__);			\
-		__p__;							\
-	})
-#endif
-
 #ifdef CONFIG_SMP
 void ipipe_set_irq_affinity(unsigned int irq, cpumask_t cpumask);
 void ipipe_send_ipi(unsigned int ipi, cpumask_t cpumask);
@@ -380,7 +351,6 @@ static inline void __ipipe_nmi_enter(void) { }
 
 static inline void __ipipe_nmi_exit(void) { }
 
-#define ipipe_safe_current()	current
 #define ipipe_processor_id()	smp_processor_id()
 
 static inline int ipipe_test_foreign_stack(void)
diff --git a/include/linux/ipipe_foreign_stack.h b/include/linux/ipipe_foreign_stack.h
new file mode 100644
index 0000000..4d5132a
--- /dev/null
+++ b/include/linux/ipipe_foreign_stack.h
@@ -0,0 +1,61 @@
+#ifndef IPIPE_FOREIGN_STACK_H
+#define IPIPE_FOREIGN_STACK_H
+
+#include <linux/ipipe_base.h>
+#include <linux/ipipe_domain.h>
+#include <asm/irqflags.h> // hard_smp_local_irq_safe
+#include <asm/ipipe.h>    // Possible per-arch definitions of ipipe_safe_current
+
+#ifdef CONFIG_IPIPE
+
+static inline void ipipe_set_foreign_stack(struct ipipe_domain *ipd)
+{
+	/* Must be called hw interrupts off. */
+	__set_bit(IPIPE_NOSTACK_FLAG, &ipipe_this_cpu_context(ipd)->status);
+}
+
+static inline void ipipe_clear_foreign_stack(struct ipipe_domain *ipd)
+{
+	/* Must be called hw interrupts off. */
+	__clear_bit(IPIPE_NOSTACK_FLAG, &ipipe_this_cpu_context(ipd)->status);
+}
+
+static inline int ipipe_test_foreign_stack(void)
+{
+	/* Must be called hw interrupts off. */
+	return test_bit(IPIPE_NOSTACK_FLAG, &__ipipe_current_context->status);
+}
+
+#ifndef ipipe_safe_current
+#define ipipe_safe_current()						\
+	({								\
+		struct task_struct *__p__;				\
+		unsigned long __flags__;				\
+		__flags__ = hard_smp_local_irq_save();			\
+		__p__ = ipipe_test_foreign_stack() ? &init_task : current; \
+		hard_smp_local_irq_restore(__flags__);			\
+		__p__;							\
+	})
+#endif
+
+#ifndef ipipe_safe_current_thread_info
+#define ipipe_safe_current_thread_info()				\
+	({								\
+		struct thread_info *__ti__;				\
+		unsigned long __flags__;				\
+		__flags__ = hard_smp_local_irq_save();			\
+		__ti__ = ipipe_test_foreign_stack() ?			\
+			&init_thread_info : current_thread_info();	\
+		hard_smp_local_irq_restore(__flags__);			\
+		__ti__;							\
+	})
+#endif
+
+#else /* !CONFIG_IPIPE */
+
+#define ipipe_safe_current()			current
+#define ipipe_safe_current_thread_info()	current_thread_info
+
+#endif /* CONFIG_IPIPE */
+
+#endif
diff --git a/kernel/ipipe/core.c b/kernel/ipipe/core.c
index 182b61c..126953b 100644
--- a/kernel/ipipe/core.c
+++ b/kernel/ipipe/core.c
@@ -33,6 +33,7 @@
 #include <linux/seq_file.h>
 #endif	/* CONFIG_PROC_FS */
 #include <linux/ipipe_trace.h>
+#include <linux/ipipe_foreign_stack.h>
 #include <linux/ipipe.h>
 
 struct ipipe_domain ipipe_root;
-- 
1.7.1



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

* [Xenomai] [PATCH 07/10] ipipe: Add mechanism to allow preemption calls from non-root context
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
                   ` (5 preceding siblings ...)
  2012-12-21 13:26 ` [Xenomai] [PATCH 06/10] ipipe: safe thread_info access from non-root context Wolfgang Mauerer
@ 2012-12-21 13:26 ` Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 08/10] ipipe: Introduce preemption call replacement mechanism Wolfgang Mauerer
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

The ipipe_safe_preempt_xyz() functions provide the same
semantics as the preempt_xyz() counterparts, but can
be safely called from non-root context.

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
---
 include/linux/ipipe_foreign_stack.h |    9 ++++++
 kernel/ipipe/core.c                 |   51 +++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/include/linux/ipipe_foreign_stack.h b/include/linux/ipipe_foreign_stack.h
index 4d5132a..0925798 100644
--- a/include/linux/ipipe_foreign_stack.h
+++ b/include/linux/ipipe_foreign_stack.h
@@ -51,6 +51,15 @@ static inline int ipipe_test_foreign_stack(void)
 	})
 #endif
 
+#define ipipe_safe_preempt_count() (ipipe_safe_current_thread_info()->preempt_count)
+
+void ipipe_safe_preempt_enable(void);
+void ipipe_safe_preempt_enable_notrace(void);
+void ipipe_safe_preempt_disable(void);
+void ipipe_safe_preempt_disable_notrace(void);
+void ipipe_safe_preempt_enable_no_resched(void);
+void ipipe_safe_preempt_enable_no_resched_notrace(void);
+
 #else /* !CONFIG_IPIPE */
 
 #define ipipe_safe_current()			current
diff --git a/kernel/ipipe/core.c b/kernel/ipipe/core.c
index 126953b..b68c772 100644
--- a/kernel/ipipe/core.c
+++ b/kernel/ipipe/core.c
@@ -1702,3 +1702,54 @@ out:
 	ipipe_restore_head(flags);
 }
 EXPORT_SYMBOL_GPL(__ipipe_post_work_root);
+
+// TODO: Provide debugging versions when CONFIG_PREEMPT_DEBUG
+// is enabled. Essentially, preempt_{en,dis}able need to be augmented
+// with tracing information
+#ifdef CONFIG_PREEMPT
+void ipipe_safe_preempt_disable(void)
+{
+	ipipe_safe_preempt_count() += 1;
+	barrier();
+}
+
+void ipipe_safe_preempt_disable_notrace(void)
+{
+	ipipe_safe_preempt_count() += 1;
+	barrier();
+}
+
+inline void ipipe_safe_preempt_enable_no_resched(void)
+{
+	barrier();
+	ipipe_safe_preempt_count() -= 1;
+}
+
+asmlinkage void preempt_schedule(void);
+inline void ipipe_safe_preempt_check_resched(void)
+{
+	if (ipipe_root_p && unlikely(test_thread_flag(TIF_NEED_RESCHED)))
+		preempt_schedule();
+}
+
+void ipipe_safe_preempt_enable(void)
+{
+	ipipe_safe_preempt_enable_no_resched();
+	barrier();
+	ipipe_safe_preempt_check_resched();
+}
+
+void ipipe_safe_preempt_enable_notrace(void)
+{
+	ipipe_safe_preempt_enable_no_resched();
+	barrier();
+	ipipe_safe_preempt_check_resched();
+}
+
+void ipipe_safe_preempt_enable_no_resched_notrace(void)
+{
+	barrier();
+	ipipe_safe_preempt_count() -= 1;
+}
+
+#endif
-- 
1.7.1



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

* [Xenomai] [PATCH 08/10] ipipe: Introduce preemption call replacement mechanism
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
                   ` (6 preceding siblings ...)
  2012-12-21 13:26 ` [Xenomai] [PATCH 07/10] ipipe: Add mechanism to allow preemption calls " Wolfgang Mauerer
@ 2012-12-21 13:26 ` Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 09/10] ipipe: Fix CONFIG_PREEMPT build Wolfgang Mauerer
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

Including <linux/ipipe_switch_preempt.h> replaces all
calls to preemption functions with calls to alternatives
that are safe in non-root context.

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
---
 include/linux/ipipe_switch_preempt.h |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/ipipe_switch_preempt.h

diff --git a/include/linux/ipipe_switch_preempt.h b/include/linux/ipipe_switch_preempt.h
new file mode 100644
index 0000000..f53919f
--- /dev/null
+++ b/include/linux/ipipe_switch_preempt.h
@@ -0,0 +1,31 @@
+#ifndef IPIPE_SWITCH_PREEMPT
+#define IPIPE_SWITCH_PREEMPT
+
+/* #include'ing this file switches the Linux preemption calls
+   to the more costly functions that may be called from non-root
+   context. */
+
+#if defined(CONFIG_IPIPE) && defined(CONFIG_PREEMPT)
+#undef preempt_count
+#define preempt_count()	ipipe_safe_preempt_count()
+
+#undef preempt_disable
+#define preempt_disable()	ipipe_safe_preempt_disable()
+
+#undef preempt_disable_notrace
+#define preempt_disable_notrace() 	ipipe_safe_preempt_disable_notrace()
+
+#undef preempt_enable
+#define preempt_enable()	ipipe_safe_preempt_enable()
+
+#undef preempt_enable_notrace
+#define preempt_enable_notrace()	ipipe_safe_preempt_enable_notrace()
+
+#undef preempt_enable_no_resched_notrace
+#define preempt_enable_no_resched_notrace()	ipipe_safe_preempt_enable_no_resched_notrace()
+
+#undef preempt_enable_no_resched
+#define preempt_enable_no_resched()	ipipe_safe_preempt_enable_no_resched()
+#endif /* CONFIG_IPIPE && CONFIG_PREEMPT */
+
+#endif
-- 
1.7.1



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

* [Xenomai] [PATCH 09/10] ipipe: Fix CONFIG_PREEMPT build
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
                   ` (7 preceding siblings ...)
  2012-12-21 13:26 ` [Xenomai] [PATCH 08/10] ipipe: Introduce preemption call replacement mechanism Wolfgang Mauerer
@ 2012-12-21 13:26 ` Wolfgang Mauerer
  2012-12-21 13:26 ` [Xenomai] [PATCH 10/10] ipipe: Make ftrace compatible with ipipe Wolfgang Mauerer
  2012-12-21 16:31 ` [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Philippe Gerum
  10 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

API change: ipipe_root_domain_p -> ipipe_root_p

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
---
 kernel/sched/core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 9fdcc22..d8e0e9e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3558,7 +3558,7 @@ asmlinkage void __sched notrace preempt_schedule(void)
 	 * we do not want to preempt the current task. Just return..
 	 */
 	if (likely(ti->preempt_count || irqs_disabled() ||
-		   !ipipe_root_domain_p))
+		   !ipipe_root_p))
 		return;
 
 	do {
-- 
1.7.1



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

* [Xenomai] [PATCH 10/10] ipipe: Make ftrace compatible with ipipe
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
                   ` (8 preceding siblings ...)
  2012-12-21 13:26 ` [Xenomai] [PATCH 09/10] ipipe: Fix CONFIG_PREEMPT build Wolfgang Mauerer
@ 2012-12-21 13:26 ` Wolfgang Mauerer
  2012-12-21 16:31 ` [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Philippe Gerum
  10 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 13:26 UTC (permalink / raw)
  To: xenomai; +Cc: jan.kiszka, wolfgang.mauerer

Replace the standard preemption definitions with the
ipipe-safe variants. Including ipipe_switch_preempt.h
into the ftrace local header trace.h is sufficient for
this because the definition propagates into all involved
C files, either directly or via trace_probe.h respectively
trace_output.h.

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@siemens.com>
---
 kernel/trace/trace.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 5aec220..50d1e9d 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -12,6 +12,7 @@
 #include <linux/hw_breakpoint.h>
 #include <linux/trace_seq.h>
 #include <linux/ftrace_event.h>
+#include <linux/ipipe_switch_preempt.h>
 
 enum trace_type {
 	__TRACE_FIRST_TYPE = 0,
-- 
1.7.1



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

* Re: [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels
  2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
                   ` (9 preceding siblings ...)
  2012-12-21 13:26 ` [Xenomai] [PATCH 10/10] ipipe: Make ftrace compatible with ipipe Wolfgang Mauerer
@ 2012-12-21 16:31 ` Philippe Gerum
  2012-12-21 16:47   ` Wolfgang Mauerer
  10 siblings, 1 reply; 13+ messages in thread
From: Philippe Gerum @ 2012-12-21 16:31 UTC (permalink / raw)
  To: Wolfgang Mauerer; +Cc: jan.kiszka, xenomai

On 12/21/2012 02:26 PM, Wolfgang Mauerer wrote:
> Hi Gilles, Jan,
>
> here's a proposal to make ipipe compatible with ftrace that
> does not require global modifications to the preemption system,
> but makes do with local changes. The approach should be easy
> to maintain in the long run:
>

In the long run, we won't have any non-linux stacks to deal with. 
Xenomai 3.x will be moving kernel-based threads over regular linux 
kthreads soon, the conversion has begun today in my local tree actually. 
I guess that nobody is going to be saddened to see this non-sense go 
away (yes, I'm the original author of this non-sense, it's painful enough).

So basically, this patches series will be required for running the 2.6.x 
series only. For this reason, on a general note, I'd like to see all 
these extra bits moving to the legacy section in a way or another 
(CONFIG_IPIPE_LEGACY).

-- 
Philippe.


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

* Re: [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels
  2012-12-21 16:31 ` [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Philippe Gerum
@ 2012-12-21 16:47   ` Wolfgang Mauerer
  0 siblings, 0 replies; 13+ messages in thread
From: Wolfgang Mauerer @ 2012-12-21 16:47 UTC (permalink / raw)
  To: Philippe Gerum; +Cc: Kiszka, Jan, xenomai@xenomai.org

On 21/12/12 17:31, Philippe Gerum wrote:
> On 12/21/2012 02:26 PM, Wolfgang Mauerer wrote:
>> Hi Gilles, Jan,
>>
>> here's a proposal to make ipipe compatible with ftrace that
>> does not require global modifications to the preemption system,
>> but makes do with local changes. The approach should be easy
>> to maintain in the long run:
>>
>
> In the long run, we won't have any non-linux stacks to deal with.
> Xenomai 3.x will be moving kernel-based threads over regular linux
> kthreads soon, the conversion has begun today in my local tree actually.
> I guess that nobody is going to be saddened to see this non-sense go
> away (yes, I'm the original author of this non-sense, it's painful enough).
>
> So basically, this patches series will be required for running the 2.6.x
> series only. For this reason, on a general note, I'd like to see all
> these extra bits moving to the legacy section in a way or another
> (CONFIG_IPIPE_LEGACY).
sure, that's easy enough to do.

Thanks, Wolfgang


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

end of thread, other threads:[~2012-12-21 16:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-21 13:26 [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Wolfgang Mauerer
2012-12-21 13:26 ` [Xenomai] [PATCH 01/10] ipipe: Add root domain guard to preempt_schedule Wolfgang Mauerer
2012-12-21 13:26 ` [Xenomai] [PATCH 02/10] ipipe: Harden clocks used by ftrace and perf Wolfgang Mauerer
2012-12-21 13:26 ` [Xenomai] [PATCH 03/10] ipipe: Harden ftrace function and function-graph tracer Wolfgang Mauerer
2012-12-21 13:26 ` [Xenomai] [PATCH 04/10] Harden trace_vbprintk for non-root use Wolfgang Mauerer
2012-12-21 13:26 ` [Xenomai] [PATCH 05/10] ipipe: Remove superfluous include file in ipipe.h Wolfgang Mauerer
2012-12-21 13:26 ` [Xenomai] [PATCH 06/10] ipipe: safe thread_info access from non-root context Wolfgang Mauerer
2012-12-21 13:26 ` [Xenomai] [PATCH 07/10] ipipe: Add mechanism to allow preemption calls " Wolfgang Mauerer
2012-12-21 13:26 ` [Xenomai] [PATCH 08/10] ipipe: Introduce preemption call replacement mechanism Wolfgang Mauerer
2012-12-21 13:26 ` [Xenomai] [PATCH 09/10] ipipe: Fix CONFIG_PREEMPT build Wolfgang Mauerer
2012-12-21 13:26 ` [Xenomai] [PATCH 10/10] ipipe: Make ftrace compatible with ipipe Wolfgang Mauerer
2012-12-21 16:31 ` [Xenomai] [RFC PATCH 0/10] Support ftrace on ipipe kernels Philippe Gerum
2012-12-21 16:47   ` Wolfgang Mauerer

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.