All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Noam Camus <noamca@mellanox.com>
Cc: "robh+dt@kernel.org" <robh+dt@kernel.org>,
	"mark.rutland@arm.com" <mark.rutland@arm.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 3/3] clocksource: Add clockevent support to NPS400 driver
Date: Mon, 14 Nov 2016 15:34:54 +0100	[thread overview]
Message-ID: <20161114143454.GE2016@mai> (raw)
In-Reply-To: <DB6PR0501MB25183C670A48F44DB916D7FEAABC0@DB6PR0501MB2518.eurprd05.prod.outlook.com>

On Mon, Nov 14, 2016 at 01:58:15PM +0000, Noam Camus wrote:
> > From: Daniel Lezcano [mailto:daniel.lezcano@linaro.org] 
> > Sent: Monday, November 14, 2016 1:23 PM
> 
> 
> >> + */
> >> +static void nps_clkevent_rm_thread(bool remove_thread) {
> >> +	unsigned int cflags;
> >> +	unsigned int enabled_threads = 0;
> >> +	int thread;
> >> +
> >> +	hw_schd_save(&cflags);
> 
> >I'm not used with hardware scheduling. Can you explain why this is needed
> >here ? What >window race we want to close ?
> We are using HW scheduling off/on in order to keep consistency of auxiliary
> registers shared among HW threads within the same core.  Example to such
> registers NPS_REG_TIMER0_TSI and NPS_REG_TIMER0_CTRL.  Since update procedure
> of these registers is not atomic we use save/restore macros to turn off/on
> the HW scheduling. This way we insure that no HW scheduling occurs and
> another HW thread (represented as another CPU) will execute in this same
> critical code path.  If we take for example nps_clkevent_add_thread() we can
> see that we are doing some read modify write to NPS_REG_TIMER0_TSI and
> optionally writing to NPS_REG_TIMER0_CTRL. This flow should be atomic and is
> protected by our save/restore macros.  Do note that interrupts are disabled
> at this point so we are safe from all asynchronous events. 
 
The function nps_clkevent_timer_event_setup() writes into the NPS_REG_TIMER0_CTRL
register but there is no critical section there. What prevents another HW thread
to write this register at the same time ?

I do believe we have a framework to access shared registers, otherwise a simple
spinlock would be simpler and perhaps faster than disabling the entire hardware
scheduling for the system, no ?

> >> +static void nps_clkevent_add_thread(bool set_event) {
> >> +	int thread;
> >> +	unsigned int cflags, enabled_threads;
> >> +
> >> +	hw_schd_save(&cflags);
> >> +
> >> +	/* add thread to TSI1 */
> >> +	thread = read_aux_reg(CTOP_AUX_THREAD_ID);
> >> +	enabled_threads = read_aux_reg(NPS_REG_TIMER0_TSI);
> >> +	enabled_threads |= (1 << thread);
> >> +	write_aux_reg(NPS_REG_TIMER0_TSI, enabled_threads);
> >> +
> >> +	/* set next timer event */
> >> +	if (set_event)
> >> +		write_aux_reg(NPS_REG_TIMER0_CTRL,
> >> +			      TIMER0_CTRL_IE | TIMER0_CTRL_NH);
> >> +
> >> +	hw_schd_restore(cflags);
> >> +}
> 
> >Not sure the boolean parameters for *_rm_thread and *_add_thread helps to
> >clarify the code. Depending on the race window with hw_schd_save/restore We
> >should be able to simplify it.
> I am not sure I am following you here, how race window may simplify this
> code?  If those routines will get no parameter I can't determine when to add
> or not (same as remove).  ...

Regarding the comment I did above, it is possible the critical section is
reduced and moved into the shutdown function. Thus, the boolean wouldn't be
needed anymore, well that is conditional to the above comment. Discard the
comment for the moment, until the hw sched vs spinlock vs NPS_REG_TIMER0_CTRL
is sorted out.

> >> +static DEFINE_PER_CPU(struct clock_event_device, nps_clockevent_device) = {
> >> +	.name				=	"NPS Timer0",
> >> +	.features			=	CLOCK_EVT_FEAT_ONESHOT |
> >> +						CLOCK_EVT_FEAT_PERIODIC,
> >> +	.rating				=	300,
> >> +	.set_next_event			=	nps_clkevent_set_next_event,
> >> +	.set_state_periodic		=	nps_clkevent_set_periodic,
> >> +	.set_state_oneshot		=	nps_clkevent_set_oneshot,
> >> +	.set_state_oneshot_stopped	=	nps_clkevent_timer_shutdown,
> >> +	.set_state_shutdown		=	nps_clkevent_timer_shutdown,
> 
> >Doesn't set_state_shutdown and set_state_oneshot_stopped need to remove the HW thread from the TSI ?
> You are correct, I will fix that.

And tick_resume. Perhaps, that is the reason why NO_HZ hangs.

-- 

 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

  reply	other threads:[~2016-11-14 14:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-13  7:24 [PATCH v5 0/3] Add clockevet for timer-nps driver to NPS400 SoC Noam Camus
2016-11-13  7:24 ` Noam Camus
2016-11-13  7:24 ` [PATCH v5 1/3] soc: Support for NPS HW scheduling Noam Camus
2016-11-13  7:24   ` Noam Camus
2016-11-13  7:24 ` [PATCH v5 2/3] clocksource: update "fn" at CLOCKSOURCE_OF_DECLARE() of nps400 timer Noam Camus
2016-11-13  7:24   ` Noam Camus
2016-11-14  8:43   ` Daniel Lezcano
2016-11-14  8:43     ` Daniel Lezcano
2016-11-13  7:24 ` [PATCH v5 3/3] clocksource: Add clockevent support to NPS400 driver Noam Camus
2016-11-13  7:24   ` Noam Camus
2016-11-14 11:23   ` Daniel Lezcano
2016-11-14 11:23     ` Daniel Lezcano
2016-11-14 13:58     ` Noam Camus
2016-11-14 14:34       ` Daniel Lezcano [this message]
2016-11-14 15:17         ` Noam Camus
2016-11-14 15:41           ` Daniel Lezcano
2016-11-14 16:45             ` Noam Camus
2016-11-14 17:10               ` Daniel Lezcano

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=20161114143454.GE2016@mai \
    --to=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=noamca@mellanox.com \
    --cc=robh+dt@kernel.org \
    --cc=tglx@linutronix.de \
    /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 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.