linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Vineet Gupta <Vineet.Gupta1@synopsys.com>
Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de
Subject: Re: [RFC PATCH v1 15/31] ARC: Process/scheduling/clock/Timers/Delay Management
Date: Mon, 12 Nov 2012 21:29:07 +0100 (CET)	[thread overview]
Message-ID: <alpine.LFD.2.02.1211122110230.10000@ionos> (raw)
In-Reply-To: <1352281674-2186-16-git-send-email-vgupta@synopsys.com>

On Wed, 7 Nov 2012, Vineet Gupta wrote:
> +void cpu_idle(void)
> +{
> +	/* Since we SLEEP in idle loop, TIF_POLLING_NRFLAG can't be set */
> +
> +	/* endless idle loop with no priority at all */
> +	while (1) {
> +		tick_nohz_idle_enter();
> +
> +		while (!need_resched())
> +			arch_idle();
> +
> +		tick_nohz_idle_exit();
> +
> +		preempt_enable_no_resched();
> +		schedule();
> +		preempt_disable();

  		schedule_preempt_disabled() please

> +	}

> diff --git a/arch/arc/kernel/time.c b/arch/arc/kernel/time.c
> 
> +static void arc_periodic_timer_setup(unsigned int limit)
> +{
> +	/* setup start and end markers */
> +	write_aux_reg(ARC_REG_TIMER0_LIMIT, limit);
> +	write_aux_reg(ARC_REG_TIMER0_CNT, 0);	/* start from 0 */
> +
> +	/* IE: Interrupt on count = limit,
> +	 * NH: Count cycles only when CPU running (NOT Halted)
> +	 */
> +	write_aux_reg(ARC_REG_TIMER0_CTRL, TIMER_CTRL_IE | TIMER_CTRL_NH);
> +}
> +
> +/*
> + * Acknowledge the interrupt & enable/disable the interrupt
> + */
> +static void arc_periodic_timer_ack(unsigned int irq_reenable)
> +{
> +	/* 1. Ack the interrupt by writing to CTRL reg.
> +	 *    Any write will cause intr to be ack, however it has to be one of
> +	 *    writable bits (NH: Count when not halted)
> +	 * 2. If required by caller, re-arm timer to Interrupt at the end of
> +	 *    next cycle.
> +	 *
> +	 * Small optimisation:
> +	 * Normal code would have been
> +	 *  if (irq_reenable) CTRL_REG = (IE | NH); else CTRL_REG = NH;
> +	 * However since IE is BIT0 we can fold the branch
> +	 */
> +	write_aux_reg(ARC_REG_TIMER0_CTRL, irq_reenable | TIMER_CTRL_NH);
> +}

....

> +/********** Clock Event Device *********/
> +
> +static int arc_clkevent_set_next_event(unsigned long delta,
> +				    struct clock_event_device *dev)
> +{
> +	arc_periodic_timer_setup(delta);

This is confusing. Is arc_periodic_timer_setup() setting up a periodic
timer or a oneshot timer? It looks you use it for both and the
differentiation happens in arc_periodic_timer_ack(). So I assume the
timer only knows about periodic mode, but you trick it into oneshot
with the ack function, right ? So it's just me being confused about
the function names, but that could do with some explanatory comments.

> +	return 0;
> +}
> +
> +static void arc_clkevent_set_mode(enum clock_event_mode mode,
> +			       struct clock_event_device *dev)
> +{
> +	pr_info("Device [%s] clockevent mode now [%d]\n", dev->name, mode);

Please remove the debug leftover.

> +	switch (mode) {
> +	case CLOCK_EVT_MODE_PERIODIC:
> +		arc_periodic_timer_setup(CONFIG_ARC_PLAT_CLK / HZ);
> +		break;
> +	case CLOCK_EVT_MODE_ONESHOT:
> +		break;
> +	default:
> +		break;
> +	}
> +
> +	return;
> +}
> +
> +static DEFINE_PER_CPU(struct clock_event_device, arc_clockevent_device) = {
> +	.name		= "ARC Timer0",
> +	.features	= CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC,
> +	.mode		= CLOCK_EVT_MODE_UNUSED,
> +	.rating		= 300,
> +	.irq		= TIMER0_IRQ,	/* hardwired, no need for resources */
> +	.set_next_event = arc_clkevent_set_next_event,
> +	.set_mode	= arc_clkevent_set_mode,
> +};
> +
> +irqreturn_t timer_irq_handler(int irq, void *dev_id)

static please

> +static int arc_finished_booting;
> +
> +/*
> + * Scheduler clock - returns current time in nanosec units.
> + * It's return value must NOT wrap around.
> + *
> + * Although the return value is nanosec units based, what's more important
> + * is whats the "source" of this value. The orig jiffies based computation
> + * was only as granular as jiffies itself (10ms on ARC).
> + * We need something that is more granular, so use the same mechanism as
> + * gettimeofday(), which uses ARC Timer T1 wrapped as a clocksource.
> + * Unfortunately the first call to sched_clock( ) is way before that subsys
> + * is initialiased, thus use the jiffies based value in the interim.
> + */
> +unsigned long long sched_clock(void)
> +{
> +	if (!arc_finished_booting) {
> +		return (unsigned long long)(jiffies - INITIAL_JIFFIES)
> +		    * (NSEC_PER_SEC / HZ);
> +	} else {
> +		struct timespec ts;
> +		getrawmonotonic(&ts);

This can live lock. sched_clock() is used by the tracer. So assume you
are function tracing and you trace a function called from within the
timekeeping seqcount write "locked" region. You spin forever in
getrawmonotonic(). Not what you want, right ?

Thanks,

	tglx

  parent reply	other threads:[~2012-11-12 20:29 UTC|newest]

Thread overview: 146+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-07  9:47 [RFC Patch v1 00/31] Synopsys ARC Linux kernel Port Vineet Gupta
2012-11-07  9:47 ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 01/31] ARC: Generic Headers Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 02/31] ARC: irqflags Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-12 19:50   ` Thomas Gleixner
2012-11-12 19:50     ` Thomas Gleixner
2013-01-01  7:44     ` Vineet Gupta
2013-01-01  7:44       ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 03/31] ARC: atomic/bitops/cmpxchg/barriers Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 04/31] asm-generic headers: uaccess.h to conditionally define segment_eq() Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 05/31] ARC: uaccess friends Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 06/31] asm-generic headers: Allow yet more arch overrides in checksum.h Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 07/31] ARC: checksum/byteorder/swab routines Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 08/31] ARC: Fundamental ARCH data-types/defines Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-08  7:10   ` Jonas Bonn
2012-11-08 18:52     ` Vineet Gupta
2012-11-08 20:36       ` Jonas Bonn
2012-11-12 13:58         ` Vineet Gupta
2012-11-12 14:12           ` Arnd Bergmann
2012-11-07  9:47 ` [RFC PATCH v1 09/31] ARC: spinlock/rwlock/mutex primitives Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 10/31] ARC: string library Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 11/31] ARC: Low level IRQ/Trap/Exception(non-MMU) Handling Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-16  4:58   ` Al Viro
2012-11-16  4:58     ` Al Viro
2012-12-27  9:00     ` Vineet Gupta
2012-12-27 13:29       ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 12/31] ARC: Interrupt Handling Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-12 20:08   ` Thomas Gleixner
2012-11-12 20:08     ` Thomas Gleixner
2013-01-01 10:46     ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 13/31] ARC: Non-MMU Exception Handling Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 14/31] ARC: syscall support Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07 14:21   ` Arnd Bergmann
2012-11-09  9:50     ` James Hogan
2012-11-13 11:41       ` James Hogan
2012-11-13 12:01         ` Jonas Bonn
2012-11-13 12:01           ` Jonas Bonn
2012-11-13 12:11           ` James Hogan
2012-11-14 12:23             ` Arnd Bergmann
2012-11-14 12:31               ` James Hogan
2012-11-13 10:13     ` Gilad Ben-Yossef
2012-11-13 10:37       ` Arnd Bergmann
2012-11-15  6:15         ` Vineet Gupta
2012-11-15  6:15           ` Vineet Gupta
2012-11-15 12:35           ` Arnd Bergmann
2013-01-17  5:13             ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 15/31] ARC: Process/scheduling/clock/Timers/Delay Management Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-12 20:29   ` Thomas Gleixner [this message]
2013-01-02  7:13     ` Vineet Gupta
2013-01-02  8:45       ` Vineet Gupta
2013-01-04 13:01       ` Frederic Weisbecker
2012-11-07  9:47 ` [RFC PATCH v1 16/31] ARC: Signal handling Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-16  5:26   ` Al Viro
2012-12-28 12:34     ` Vineet Gupta
2012-12-28 12:34       ` Vineet Gupta
2012-12-28 12:42       ` [PATCH 1/2] ARC: [Review] Preparing to fix incorrect syscall restarts due to signals Vineet Gupta
2012-12-28 12:42         ` [PATCH 2/2] ARC: [Review] Prevent incorrect syscall restarts Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 17/31] ARC: Cache Flush Management Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 18/31] ARC: Page Table Management Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 19/31] ARC: MMU Context Management Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 20/31] ARC: MMU Exception Handling Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 21/31] ARC: TLB flush Handling Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 22/31] ARC: Page Fault handling (incl uaccess fixup) Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 23/31] ARC: I/O and DMA Mappings Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 24/31] ARC: startup #1: low-level, setup_arch(), /proc/cpuinfo, mem init Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 25/31] ARC: [plat-arcfpga] Hooking up platform to ARC UART Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07 14:16   ` Arnd Bergmann
2012-11-07 14:16     ` Arnd Bergmann
2013-01-07 13:10     ` Vineet Gupta
2013-01-07 13:46       ` Arnd Bergmann
2013-01-07 14:04         ` Vineet Gupta
2013-01-07 14:36           ` Arnd Bergmann
2013-01-14  7:35     ` early init dt for earlyprintk (was Re: [RFC PATCH v1 25/31] ARC: [plat-arcfpga] Hooking up platform to ARC UART) Vineet Gupta
2013-01-14  9:48       ` James Hogan
2013-01-14 10:09         ` Vineet Gupta
2013-01-14 10:54       ` Arnd Bergmann
2013-01-17  7:29     ` [RFC PATCH v1 25/31] ARC: [plat-arcfpga] Hooking up platform to ARC UART Vineet Gupta
2013-01-17 10:52       ` Arnd Bergmann
2012-11-07  9:47 ` [RFC PATCH v1 26/31] ARC: Build system: Makefiles, Kconfig, Linker script Vineet Gupta
2012-11-07 14:13   ` Arnd Bergmann
     [not found]     ` <50E4449A.7010606@synopsys.com>
     [not found]       ` <201301021448.20119.arnd@arndb.de>
2013-01-03  7:58         ` Vineet Gupta
2013-01-03  8:25           ` Arnd Bergmann
2013-01-03  8:25             ` Arnd Bergmann
2013-03-11 12:29     ` SYSV IPC broken for no-legacy syscall kernels (was Re: [RFC PATCH v1 26/31] ARC: Build system: Makefiles, Kconfig, Linker script) Vineet Gupta
2013-03-11 12:44       ` James Hogan
2013-03-11 12:56         ` Vineet Gupta
2013-03-11 13:07           ` James Hogan
2013-03-11 13:30             ` Arnd Bergmann
2013-03-11 13:48               ` Vineet Gupta
2013-03-11 13:48                 ` Vineet Gupta
2013-03-11 14:50                 ` Arnd Bergmann
2012-11-15 17:49   ` [RFC PATCH v1 26/31] ARC: Build system: Makefiles, Kconfig, Linker script James Hogan
2012-11-15 17:49     ` James Hogan
2012-11-15 19:30     ` Ralf Baechle
2012-11-16  6:36       ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 27/31] ARC: Last bits (stubs) to get to a running kernel with UART Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 28/31] ARC: split ret_from_fork, simplify kernel_thread() Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 29/31] ARC: switch to generic kernel_thread() Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 30/31] ARC: switch to generic kernel_execve() and sys_execve() Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-16  4:08   ` Al Viro
2012-11-16  4:08     ` Al Viro
2012-11-17 14:01     ` Vineet Gupta
2012-11-07  9:47 ` [RFC PATCH v1 31/31] ARC: [plat-arcfpga] defconfig Vineet Gupta
2012-11-07  9:47   ` Vineet Gupta
2012-11-07 14:06   ` Arnd Bergmann
2012-11-12 14:18     ` James Hogan
2012-11-12 14:21       ` Arnd Bergmann
2012-11-07 14:36 ` [RFC Patch v1 00/31] Synopsys ARC Linux kernel Port Arnd Bergmann
2012-11-08 19:09   ` Vineet Gupta
2012-11-07 20:46 ` Gilad Ben-Yossef
2012-11-07 20:46   ` Gilad Ben-Yossef
2012-11-20 13:47 ` Pavel Machek
2012-11-20 13:49   ` Vineet Gupta
2012-11-20 13:59   ` Pavel Machek
2012-11-20 14:17     ` Vineet Gupta
2013-01-18 19:46       ` Pavel Machek
2013-01-18 22:17         ` Arnd Bergmann
2013-01-19 10:15           ` Pavel Machek
2013-01-19 12:32         ` Vineet Gupta
2013-01-19 17:02           ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.02.1211122110230.10000@ionos \
    --to=tglx@linutronix.de \
    --cc=Vineet.Gupta1@synopsys.com \
    --cc=arnd@arndb.de \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).