lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170804125102.vrukamkpcnxvgkd5@hirez.programming.kicks-ass.net>
Date:   Fri, 4 Aug 2017 14:51:02 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Alexey Budankov <alexey.budankov@...ux.intel.com>
Cc:     Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Andi Kleen <ak@...ux.intel.com>,
        Kan Liang <kan.liang@...el.com>,
        Dmitri Prokhorov <Dmitry.Prohorov@...el.com>,
        Valery Cherepennikov <valery.cherepennikov@...el.com>,
        Mark Rutland <mark.rutland@....com>,
        Stephane Eranian <eranian@...gle.com>,
        David Carrillo-Cisneros <davidcc@...gle.com>,
        linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v6 2/3]: perf/core: use context tstamp_data for skipped
 events on mux interrupt

On Fri, Aug 04, 2017 at 02:35:34PM +0200, Peter Zijlstra wrote:
> Something like:
> 
> __update_state_and_time(event, new_state)
> {
> 	u64 delta, now = perf_event_time(event);
> 	int old_state = event->state;
> 
> 	event->tstamp = now;
> 	event->state  = new_state;
> 
> 	delta = now - event->tstamp;
Obv should go above the tstamp assignment

> 	switch (state) {
> 	case STATE_ACTIVE:
> 		WARN_ON_ONCE(old_state != STATE_INACTIVE);
> 		event->total_time_enabled += delta;
> 		break;
> 
> 	case STATE_INACTIVE:
> 		switch (old_state) {
> 		case STATE_OFF:
> 			/* ignore the OFF -> INACTIVE period */
> 			break;
> 
> 		case STATE_ACTIVE:
> 			event->total_time_enabled += delta;
> 			event->total_time_running += delta;
> 			break;
> 
> 		default:
> 			WARN_ONCE();
> 		}
> 		break;
> 
> 	case STATE_OFF:
> 		WARN_ON_ONCE(old_state != STATE_INACTIVE)
> 		event->total_time_enabled += delta;
> 		break;
> 	}
> }

So that's a straight fwd state machine that deals with:

  OFF <-> INACTIVE <-> ACTIVE

but I think something like:

__update_state_and_time(event, new_state)
{
	u64 delta, new = perf_event_time(event);
	int old_state = event->state;

	delta = now - event->tstamp;
	event->tstamp = now;
	event->state  = new_state;

	if (old_state == STATE_OFF)
		return;

	event->total_time_enabled += delta;

	if (old_state == STATE_ACTIVE)
		event->total_time_running += delta;
}

is equivalent and generates smaller code.. but again, double check (also
it doesn't validate the state transitions).

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ