From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id C56E5A04BE;
	Sun,  6 Sep 2020 23:44:18 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id D3E692BAB;
	Sun,  6 Sep 2020 23:44:17 +0200 (CEST)
Received: from mga14.intel.com (mga14.intel.com [192.55.52.115])
 by dpdk.org (Postfix) with ESMTP id 94DE91DB8
 for <dev@dpdk.org>; Sun,  6 Sep 2020 23:44:15 +0200 (CEST)
IronPort-SDR: N/XNbDp5S9+X2sdojBITov5PMpSZeQgg7xVcDpy+x0LEaB0NtAUFaTe54O683zXPvfGwgE7du9
 HcyJlEpcV/mw==
X-IronPort-AV: E=McAfee;i="6000,8403,9736"; a="157194441"
X-IronPort-AV: E=Sophos;i="5.76,399,1592895600"; d="scan'208";a="157194441"
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga004.jf.intel.com ([10.7.209.38])
 by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 06 Sep 2020 14:44:13 -0700
IronPort-SDR: xVgm4KWeAUT+DJ3eIqP/XhnFm2J3YqUexDfyF6RVqo4ay2HBVWuReHy+V2hDBGxb1b7dnfgmtf
 M1WLJ3kId4aw==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.76,399,1592895600"; d="scan'208";a="448173175"
Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14])
 by orsmga004.jf.intel.com with ESMTP; 06 Sep 2020 14:44:13 -0700
Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by
 ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.1.1713.5; Sun, 6 Sep 2020 14:44:12 -0700
Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by
 orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5
 via Frontend Transport; Sun, 6 Sep 2020 14:44:12 -0700
Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.36.55) by
 edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.1.1713.5; Sun, 6 Sep 2020 14:44:12 -0700
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=muoCJwYTXjaY5+RcoGFpzdseHBdBOT2HcyMm6lfzhSdMthN/8P57odZMu89mLDVBQ44sNS6cmnZLViWVLRrk3Bm4v/Yxsg6E7heT8RhwQgfdv2N3pVTZmPGKMDdbyx2FrocjbOxFJreVKDzJ6q6/bIkft6/EAOqMjIFOp3oTd7okmls7kDuxtAfI53ga4Xh/y57MeP2dIfwVCsQu112DVNN7KB21Ps+2j72axeDkkG2fVsFHMd0VV/6lpHrWMEJFHKAfRNYyUnCp/744o/uwoArHmzyjM+5vxYj4TdAkFB8buul35C694JLT5Cl8YO4WjZdy8OGHF9nzsgL6Xq8nhQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=znw+7IrrQIj9QuK3Vg/tJ/FYnsaJbjw/X0rTAXqoHZc=;
 b=cPr+n0mig7Q6PIVN6zup2cdipA/p5l+qDyqKTs2LC72b5Zi2w3IQ8ZqZJc5dcPYdZldJ2XACuMhRePV56o0JUldvVKLtQqgGgEfqmbw1nWddznMun+x6bjYWVADHM/n26jlL4pgXNrmPdgye+djG22FRReeJvHh6nb9F4KVqufA0CHR4uANSfg+DJdnxQsfVxSubvEhOE4OLO9poTQEiQ/8qoqDoZIZ/g7LlwuWGBxd5qbWzr2ad7kf5Dx/RM82RYIUfuizGwkOkiWGmDhEOlh2WWT2NPH8YbxE52OOwuuEYr3i6InRBR0HYl5UVjJxTISguK73Kf7Hj2x9eCxL17g==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com;
 dkim=pass header.d=intel.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; 
 s=selector2-intel-onmicrosoft-com;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=znw+7IrrQIj9QuK3Vg/tJ/FYnsaJbjw/X0rTAXqoHZc=;
 b=eD6TQV+68pI/dCS/rAzqQtXlACDkjwBKbThuWuL5PzwkzN6+JIxLtmuz1ALps1m8eHjixcDvuVXBaweAV/tUavubMUGz67XXKZxjwGIU0wXmK0ZDeZYsv3pr7l6UIWjrpv52ADVfdYkwQUP02BVvhuPGjv+Cu/4WjkX+F4JEmBk=
Received: from BYAPR11MB3301.namprd11.prod.outlook.com (2603:10b6:a03:7f::26)
 by BYAPR11MB3719.namprd11.prod.outlook.com (2603:10b6:a03:fa::24)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Sun, 6 Sep
 2020 21:44:09 +0000
Received: from BYAPR11MB3301.namprd11.prod.outlook.com
 ([fe80::f43b:a137:dab8:8b0b]) by BYAPR11MB3301.namprd11.prod.outlook.com
 ([fe80::f43b:a137:dab8:8b0b%6]) with mapi id 15.20.3348.019; Sun, 6 Sep 2020
 21:44:09 +0000
From: "Ananyev, Konstantin" <konstantin.ananyev@intel.com>
To: "Ma, Liang J" <liang.j.ma@intel.com>, "dev@dpdk.org" <dev@dpdk.org>
CC: "Hunt, David" <david.hunt@intel.com>, "Burakov, Anatoly"
 <anatoly.burakov@intel.com>, "Ma, Liang J" <liang.j.ma@intel.com>
Thread-Topic: [dpdk-dev] [PATCH v3 1/6] eal: add power management intrinsics
Thread-Index: AQHWgqTjCQ9gH9c6wEeOXToY9nJ+SKlcJ8Dg
Date: Sun, 6 Sep 2020 21:44:09 +0000
Message-ID: <BYAPR11MB3301052E77F9088FD0643B4A9A2B0@BYAPR11MB3301.namprd11.prod.outlook.com>
References: <1597141666-20621-1-git-send-email-liang.j.ma@intel.com>
 <1599214740-3927-1-git-send-email-liang.j.ma@intel.com>
In-Reply-To: <1599214740-3927-1-git-send-email-liang.j.ma@intel.com>
Accept-Language: en-GB, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
dlp-product: dlpe-windows
dlp-reaction: no-action
dlp-version: 11.5.1.3
authentication-results: intel.com; dkim=none (message not signed)
 header.d=none;intel.com; dmarc=none action=none header.from=intel.com;
x-originating-ip: [46.7.39.127]
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: fefaf9b0-af72-46b2-94da-08d852adfcdf
x-ms-traffictypediagnostic: BYAPR11MB3719:
x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr
x-ms-exchange-transport-forked: True
x-microsoft-antispam-prvs: <BYAPR11MB3719314C6C92E7C1E68DB38D9A2B0@BYAPR11MB3719.namprd11.prod.outlook.com>
x-ms-oob-tlc-oobclassifiers: OLM:10000;
x-ms-exchange-senderadcheck: 1
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: vUSQkTWMxgbds4cgRPveZbLieBGa6Yr0mhgivfKF7mbeV3Rrya5wUJ8atuU4Ppb0Ywh/Hieb7Xmu71x+jM53SDGYzmFX5siAovZFKadlX79+rTtxeY8nnbfTAKroJ4UFLUgKUBq5N6wROR6MhoKuizI7eLCARUMpo0XbMKOS4jF9dCzDe3Reyt5qKuouAJ8rJ4qGR3h+Ri7cfBRGo6UJZRNUCVomI+ZVnKkleEzDpTm6oMqTAlvcLa07C4ozt1O6Y22pWGaWGwIahpustNZqiglCsDBrqlsbUcj4Oq4Ah7ZAT7BqGSwfWMB4ciLN4cqU
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:BYAPR11MB3301.namprd11.prod.outlook.com; PTR:; CAT:NONE;
 SFS:(4636009)(39860400002)(376002)(136003)(346002)(396003)(366004)(5660300002)(2906002)(52536014)(66476007)(66556008)(76116006)(66946007)(86362001)(66446008)(33656002)(83380400001)(64756008)(71200400001)(8936002)(26005)(9686003)(7696005)(55016002)(6506007)(186003)(316002)(110136005)(54906003)(478600001)(107886003)(4326008)(8676002);
 DIR:OUT; SFP:1102; 
x-ms-exchange-antispam-messagedata: sEyCMT/2MfIFA3ZBZDO9pPwHGCwerlUrIhi6i5e0eFWu42vxab6ypMYkBMJCsFzjfIlaQCYaOD7iPpVRtMDZOdrmVET8jAF7j1KpQLZQ/iI1c6VdlZf/tFw0gFAdqW3p/muRjcJ4kpqQMLJb9xcbTzL/l5nkMa+0efZJwfO/QlSkToR718sERvAYiHzdVNKqN5+bgQAp8WdEYi/NtJCm1o7nMRLHhfjzL1SSXAy0q2kItHHLkHX0alMiih/Kg0IJ020rA42eG3BPYKKemkJibiGWUGAC3zrpYt788Gs4mofoK8nfAxP1M6kY5SK0XtT28S2dUTXmxVuuO455fAtl75MG17GNqJKHFtO/KIMsBlUOhj9DWexv3ER6wlXixnVSU6fWcs9QNe9Hz1by8+33eNkbJ20EucOe3S+hyq76EsdrUngblBYryABU+LNc37hp8yw9+FXMQjHyylJTpRSDOSvS55D3L12tQf35J4EvVKD/up/Sx2KEkMonxJyWhtgRs08DUJpN6ILN88sKUxwot1+p4ZSSt5323pV8q3En/3c/e8Yzjy94ar9UuEqSylM5N46J8Chgwpy9arU6kKtkpwj6mDftMJ7a8BYLtGIgpTs404B6kA4WgxpbfZnJ+MEtGPzN0E5gGyjEkOCQqwkmSw==
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB3301.namprd11.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: fefaf9b0-af72-46b2-94da-08d852adfcdf
X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Sep 2020 21:44:09.5885 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: OS9ALTsjAxGGZVPJT3w3gE9zL8Wsb9axQXshP9yH91glZxkJc+XVHRHjc1mubLUzsOZrJReT0KUOGGiSWcfZ1jGkFAu43lF7lsLhRMglWbA=
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3719
X-OriginatorOrg: intel.com
Subject: Re: [dpdk-dev] [PATCH v3 1/6] eal: add power management intrinsics
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>


> diff --git a/lib/librte_eal/x86/include/rte_power_intrinsics.h b/lib/libr=
te_eal/x86/include/rte_power_intrinsics.h
> new file mode 100644
> index 0000000000..6dd1cdc939
> --- /dev/null
> +++ b/lib/librte_eal/x86/include/rte_power_intrinsics.h
> @@ -0,0 +1,143 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2020 Intel Corporation
> + */
> +
> +#ifndef _RTE_POWER_INTRINSIC_X86_64_H_
> +#define _RTE_POWER_INTRINSIC_X86_64_H_

As a nit - if the function below are supported for both 64 and 32 ISA,
then probably: RTE_POWER_INTRINSIC_X86_H_


> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +#include <rte_atomic.h>
> +#include <rte_common.h>
> +
> +#include "generic/rte_power_intrinsics.h"
> +
> +/**
> + * Monitor specific address for changes. This will cause the CPU to ente=
r an
> + * architecture-defined optimized power state until either the specified
> + * memory address is written to, or a certain TSC timestamp is reached.
> + *
> + * Additionally, an `expected` 64-bit value and 64-bit mask are provided=
. If
> + * mask is non-zero, the current value pointed to by the `p` pointer wil=
l be
> + * checked against the expected value, and if they match, the entering o=
f
> + * optimized power state may be aborted.
> + *
> + * This function uses UMONITOR/UMWAIT instructions. For more information=
 about
> + * their usage, please refer to Intel(R) 64 and IA-32 Architectures Soft=
ware
> + * Developer's Manual.
> + *
> + * @param p
> + *   Address to monitor for changes. Must be aligned on an 64-byte bound=
ary.
> + * @param expected_value
> + *   Before attempting the monitoring, the `p` address may be read and c=
ompared
> + *   against this value. If `value_mask` is zero, this step will be skip=
ped.
> + * @param value_mask
> + *   The 64-bit mask to use to extract current value from `p`.
> + * @param state
> + *   Architecture-dependent optimized power state number. Can be 0 (C0.2=
) or
> + *   1 (C0.1).
> + * @param tsc_timestamp
> + *   Maximum TSC timestamp to wait for.
> + *
> + * @return
> + *   - 1 if wakeup was due to TSC timeout expiration.
> + *   - 0 if wakeup was due to memory write or other reasons.
> + */
> +static inline int rte_power_monitor(const volatile void *p,
> +		const uint64_t expected_value, const uint64_t value_mask,
> +		const uint32_t state, const uint64_t tsc_timestamp)
> +{
> +	const uint32_t tsc_l =3D (uint32_t)tsc_timestamp;
> +	const uint32_t tsc_h =3D (uint32_t)(tsc_timestamp >> 32);
> +	/* the rflags need match native register size */
> +#ifdef RTE_ARCH_I686
> +	uint32_t rflags;
> +#else
> +	uint64_t rflags;
> +#endif
> +	/*
> +	 * we're using raw byte codes for now as only the newest compiler
> +	 * versions support this instruction natively.
> +	 */
> +
> +	/* set address for UMONITOR */
> +	asm volatile(".byte 0xf3, 0x0f, 0xae, 0xf7;"
> +			:
> +			: "D"(p));
> +
> +	if (value_mask) {
> +		const uint64_t cur_value =3D *(const volatile uint64_t *)p;
> +		const uint64_t masked =3D cur_value & value_mask;
> +		/* if the masked value is already matching, abort */
> +		if (masked =3D=3D expected_value)
> +			return 0;
> +	}
> +	/* execute UMWAIT */
> +	asm volatile(".byte 0xf2, 0x0f, 0xae, 0xf7;\n"
> +		/*
> +		 * UMWAIT sets CF flag in RFLAGS, so PUSHF to push them
> +		 * onto the stack, then pop them back into `rflags` so that
> +		 * we can read it.
> +		 */
> +		"pushf;\n"
> +		"pop %0;\n"
> +		: "=3Dr"(rflags)
> +		: "D"(state), "a"(tsc_l), "d"(tsc_h));
> +
> +	/* we're interested in the first bit (the carry flag) */
> +	return rflags & 0x1;
> +}
> +
> +/**
> + * Enter an architecture-defined optimized power state until a certain T=
SC
> + * timestamp is reached.
> + *
> + * This function uses TPAUSE instruction. For more information about its=
 usage,
> + * please refer to Intel(R) 64 and IA-32 Architectures Software Develope=
r's
> + * Manual.
> + *
> + * @param state
> + *   Architecture-dependent optimized power state number. Can be 0 (C0.2=
) or
> + *   1 (C0.1).
> + * @param tsc_timestamp
> + *   Maximum TSC timestamp to wait for.
> + *
> + * @return
> + *   - 1 if wakeup was due to TSC timeout expiration.
> + *   - 0 if wakeup was due to other reasons.
> + */
> +static inline int rte_power_pause(const uint32_t state,
> +		const uint64_t tsc_timestamp)
> +{
> +	const uint32_t tsc_l =3D (uint32_t)tsc_timestamp;
> +	const uint32_t tsc_h =3D (uint32_t)(tsc_timestamp >> 32);
> +	/* the rflags need match native register size */
> +#ifdef RTE_ARCH_I686
> +	uint32_t rflags;
> +#else
> +	uint64_t rflags;
> +#endif
> +
> +	/* execute TPAUSE */
> +	asm volatile(".byte 0x66, 0x0f, 0xae, 0xf7;\n"
> +		     /*
> +		      * TPAUSE sets CF flag in RFLAGS, so PUSHF to push them
> +		      * onto the stack, then pop them back into `rflags` so that
> +		      * we can read it.
> +		      */
> +		     "pushf;\n"
> +		     "pop %0;\n"
> +		     : "=3Dr"(rflags)
> +		     : "D"(state), "a"(tsc_l), "d"(tsc_h));
> +
> +	/* we're interested in the first bit (the carry flag) */
> +	return rflags & 0x1;
> +}
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* _RTE_POWER_INTRINSIC_X86_64_H_ */