From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568266764; cv=none; d=zoho.com; s=zohoarc; b=MmhfGTisB5d8XQmRDD/Sifz9wZlT96jdT3kRRTBi6jPexBd+KmYJ2RZPgKPOOJi0onAOIX8YzlcATtU3kG62rRv4h8fbwuTDcjWiNhyG2eJotP3cqHaoMNBTFJYtFKp+gqAq6bzVRSmSCdhC0HcGIdMtu1j9NJcTQuecY5lzFdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568266764; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=HhJvX3sRCCATJAVQw+VbO6+zcPjYlN9YNT+yhSxNHn0=; b=kbV/inqMaNiVOPUO853In6hsy7seaUko9VAL2lWAPWz7A2z95mk+whMmnLCMMSAAkHhm4eGvQSavFUMz1G9vWo08YGNnMO2qMrk+Uev2hxVi5NHmp8/jXvEjbBZ+xm5vAE92u4pPMpk8+hPxt1TehIFpdUjvcTnmnxkz8QtuM3s= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568266763995174.86349952700652; Wed, 11 Sep 2019 22:39:23 -0700 (PDT) Received: from localhost ([::1]:58228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8HpB-00059w-En for importer@patchew.org; Thu, 12 Sep 2019 01:39:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56508) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hmt-0003TA-IO for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hmq-0002vf-K4 for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:36:58 -0400 Received: from mga11.intel.com ([192.55.52.93]:18593) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hmo-0002tG-NP for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:36:56 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:36:45 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:36:44 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030745" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:28 +0800 Message-Id: <20190912053638.4858-2-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 01/11] util/cutils: Add qemu_strtotime_ps() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, jonathan.cameron@huawei.com, dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" To convert strings with time suffixes to numbers, support time unit are "ps" for picosecond, "ns" for nanosecond, "us" for microsecond, "ms" for millisecond or "s" for second. Signed-off-by: Tao Xu --- No changes in v11. New patch in v10. --- include/qemu/cutils.h | 1 + util/cutils.c | 82 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 12301340a4..0e70a807e1 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -180,5 +180,6 @@ int uleb128_decode_small(const uint8_t *in, uint32_t *n= ); * *str1 is <, =3D=3D or > than *str2. */ int qemu_pstrcmp0(const char **str1, const char **str2); +int qemu_strtotime_ps(const char *nptr, const char **end, uint64_t *result= ); =20 #endif diff --git a/util/cutils.c b/util/cutils.c index fd591cadf0..a50c15f46a 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -847,3 +847,85 @@ int qemu_pstrcmp0(const char **str1, const char **str2) { return g_strcmp0(*str1, *str2); } + +static int64_t timeunit_mul(const char *unitstr) +{ + if (g_strcmp0(unitstr, "ps") =3D=3D 0) { + return 1; + } else if (g_strcmp0(unitstr, "ns") =3D=3D 0) { + return 1000; + } else if (g_strcmp0(unitstr, "us") =3D=3D 0) { + return 1000000; + } else if (g_strcmp0(unitstr, "ms") =3D=3D 0) { + return 1000000000LL; + } else if (g_strcmp0(unitstr, "s") =3D=3D 0) { + return 1000000000000LL; + } else { + return -1; + } +} + + +/* + * Convert string to time, support time unit are ps for picosecond, + * ns for nanosecond, us for microsecond, ms for millisecond or s for seco= nd. + * End pointer will be returned in *end, if not NULL. Return -ERANGE on + * overflow, and -EINVAL on other error. + */ +static int do_strtotime(const char *nptr, const char **end, + const char *default_unit, uint64_t *result) +{ + int retval; + const char *endptr; + int mul_required =3D 0; + int64_t mul; + double val, integral, fraction; + + retval =3D qemu_strtod_finite(nptr, &endptr, &val); + if (retval) { + goto out; + } + fraction =3D modf(val, &integral); + if (fraction !=3D 0) { + mul_required =3D 1; + } + + mul =3D timeunit_mul(endptr); + + if (mul =3D=3D 1000000000000LL) { + endptr++; + } else if (mul !=3D -1) { + endptr +=3D 2; + } else { + mul =3D timeunit_mul(default_unit); + assert(mul >=3D 0); + } + if (mul =3D=3D 1 && mul_required) { + retval =3D -EINVAL; + goto out; + } + /* + * Values >=3D 0xfffffffffffffc00 overflow uint64_t after their trip + * through double (53 bits of precision). + */ + if ((val * (double)mul >=3D 0xfffffffffffffc00) || val < 0) { + retval =3D -ERANGE; + goto out; + } + *result =3D val * (double)mul; + retval =3D 0; + +out: + if (end) { + *end =3D endptr; + } else if (*endptr) { + retval =3D -EINVAL; + } + + return retval; +} + +int qemu_strtotime_ps(const char *nptr, const char **end, uint64_t *result) +{ + return do_strtotime(nptr, end, "ps", result); +} --=20 2.20.1 From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568266767; cv=none; d=zoho.com; s=zohoarc; b=Ll8BU6fGF1JcN71Smjp1C/aDS+q9uEqAX/RhTnT4xRr6/FzG21mWGKlXIGiS6dHl15iWXLmkyXqzbdvBPg+SmqLTYg8stTU7Ofp8JVH2MPkzl0kEftTSKwNGtSSxBLZzaHbpXkQEh5UoK9nlncALA6oYoHsGeKZSYEckY4Y0z5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568266767; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ecg9hER5vpb6OH3Nrj7s/1c6NuEgCTR14KrmaVehfY4=; b=RRWOW5cKRRVTqr4JUC4cviNNI/jUcZrIp25ImLZc9lN8Hed+HNlVa8cyZVr/KHNC2Ud1ZCupU3HFZIXjR34DsIcWFP3sBCry444BwctnoE5smCD3veYulOI7AHJ9PmhG3tOqi4qDTLy4FRKTvOBz6mqOr4q8JYCzFtsd2OWXkSM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568266767632917.976411454956; Wed, 11 Sep 2019 22:39:27 -0700 (PDT) Received: from localhost ([::1]:58230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8HpD-0005As-Bt for importer@patchew.org; Thu, 12 Sep 2019 01:39:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56507) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hmt-0003T9-JX for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hmq-0002vs-L6 for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:36:58 -0400 Received: from mga11.intel.com ([192.55.52.93]:18596) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hmo-0002tc-NT for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:36:56 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:36:47 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:36:45 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030753" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:29 +0800 Message-Id: <20190912053638.4858-3-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 02/11] tests/cutils: Add test for qemu_strtotime_ps() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, jonathan.cameron@huawei.com, dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Test the input of basic, time suffixes, float, invaild, trailing and overflow. Signed-off-by: Tao Xu --- No changes in v11. New patch in v10. --- tests/test-cutils.c | 199 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/tests/test-cutils.c b/tests/test-cutils.c index 1aa8351520..19c967d3d5 100644 --- a/tests/test-cutils.c +++ b/tests/test-cutils.c @@ -2179,6 +2179,193 @@ static void test_qemu_strtosz_metric(void) g_assert(endptr =3D=3D str + 6); } =20 +static void test_qemu_strtotime_ps_simple(void) +{ + const char *str; + const char *endptr; + int err; + uint64_t res =3D 0xbaadf00d; + + str =3D "0"; + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 0); + g_assert(endptr =3D=3D str + 1); + + str =3D "56789"; + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 56789); + g_assert(endptr =3D=3D str + 5); + + err =3D qemu_strtotime_ps(str, NULL, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 56789); + + /* Note: precision is 53 bits since we're parsing with strtod() */ + + str =3D "9007199254740991"; /* 2^53-1 */ + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 0x1fffffffffffff); + g_assert(endptr =3D=3D str + 16); + + str =3D "9007199254740992"; /* 2^53 */ + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 0x20000000000000); + g_assert(endptr =3D=3D str + 16); + + str =3D "9007199254740993"; /* 2^53+1 */ + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 0x20000000000000); /* rounded to 53 bits = */ + g_assert(endptr =3D=3D str + 16); + + str =3D "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */ + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 0xfffffffffffff800); + g_assert(endptr =3D=3D str + 20); + + str =3D "18446744073709550591"; /* 0xfffffffffffffbff */ + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 0xfffffffffffff800); /* rounded to 53 bit= s */ + g_assert(endptr =3D=3D str + 20); + + /* 0x7ffffffffffffe00..0x7fffffffffffffff get rounded to + * 0x8000000000000000, thus -ERANGE; see test_qemu_strtosz_erange() */ +} + +static void test_qemu_strtotime_ps_units(void) +{ + const char *ps =3D "1ps"; + const char *ns =3D "1ns"; + const char *us =3D "1us"; + const char *ms =3D "1ms"; + const char *s =3D "1s"; + int err; + const char *endptr; + uint64_t res =3D 0xbaadf00d; + + err =3D qemu_strtotime_ps(ps, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 1); + g_assert(endptr =3D=3D ps + 3); + + err =3D qemu_strtotime_ps(ns, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 1000); + g_assert(endptr =3D=3D ns + 3); + + err =3D qemu_strtotime_ps(us, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 1000000); + g_assert(endptr =3D=3D us + 3); + + err =3D qemu_strtotime_ps(ms, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 1000000000LL); + g_assert(endptr =3D=3D ms + 3); + + err =3D qemu_strtotime_ps(s, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 1000000000000ULL); + g_assert(endptr =3D=3D s + 2); +} + +static void test_qemu_strtotime_ps_float(void) +{ + const char *str =3D "56.789ns"; + int err; + const char *endptr; + uint64_t res =3D 0xbaadf00d; + + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 56.789 * 1000); + g_assert(endptr =3D=3D str + 8); +} + +static void test_qemu_strtotime_ps_invalid(void) +{ + const char *str; + const char *endptr; + int err; + uint64_t res =3D 0xbaadf00d; + + str =3D ""; + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + g_assert(endptr =3D=3D str); + + str =3D " \t "; + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + g_assert(endptr =3D=3D str); + + str =3D "crap"; + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + g_assert(endptr =3D=3D str); + + str =3D "inf"; + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + g_assert(endptr =3D=3D str); + + str =3D "NaN"; + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + g_assert(endptr =3D=3D str); +} + +static void test_qemu_strtotime_ps_trailing(void) +{ + const char *str; + int err; + uint64_t res =3D 0xbaadf00d; + + str =3D "123xxx"; + + err =3D qemu_strtotime_ps(str, NULL, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); +} + +static void test_qemu_strtotime_ps_erange(void) +{ + const char *str; + const char *endptr; + int err; + uint64_t res =3D 0xbaadf00d; + + str =3D "-1"; + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -ERANGE); + g_assert(endptr =3D=3D str + 2); + + str =3D "18446744073709550592"; /* 0xfffffffffffffc00 */ + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -ERANGE); + g_assert(endptr =3D=3D str + 20); + + str =3D "18446744073709551615"; /* 2^64-1 */ + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -ERANGE); + g_assert(endptr =3D=3D str + 20); + + str =3D "18446744073709551616"; /* 2^64 */ + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -ERANGE); + g_assert(endptr =3D=3D str + 20); + + str =3D "200000000000000s"; + err =3D qemu_strtotime_ps(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -ERANGE); + g_assert(endptr =3D=3D str + 16); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -2456,5 +2643,17 @@ int main(int argc, char **argv) g_test_add_func("/cutils/strtosz/metric", test_qemu_strtosz_metric); =20 + g_test_add_func("/cutils/strtotime/simple", + test_qemu_strtotime_ps_simple); + g_test_add_func("/cutils/strtotime/units", + test_qemu_strtotime_ps_units); + g_test_add_func("/cutils/strtotime/float", + test_qemu_strtotime_ps_float); + g_test_add_func("/cutils/strtotime/invalid", + test_qemu_strtotime_ps_invalid); + g_test_add_func("/cutils/strtotime/trailing", + test_qemu_strtotime_ps_trailing); + g_test_add_func("/cutils/strtotime/erange", + test_qemu_strtotime_ps_erange); return g_test_run(); } --=20 2.20.1 From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568266770; cv=none; d=zoho.com; s=zohoarc; b=fAyuIhRBLj6W/YAeD/ZRA0okCYFtH9un6gDpopahzldevS1ROfhnhqDrDCOgdkrZOPpRri6yUa3iOlbdLGOPLj6JcJR3oXxf0XjYFv+utZbfQgqRMWMCihB+1XGDen827A5/jMy9cnu0QnmiDIfcRwwjdhPUHFdL0RaN7eNyGyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568266770; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=YZSeOSNPwkaPbApgfGUuxywju4fVGv4IstnC0iVdeRU=; b=KxdY7q9KF/AwOFNteVLjQgUxb15KkXDWhhuYc1BNCECZxN/TBELBXUFAObPNxMI7EXgA/DsSyxXhoOBaEIo0zV2lgrL9PQjy0hBT/MegJOapLG8IWItJLmR1FTdpQnqo5j5Nf2fAOSnWrkAX3raJ1Aft5WYfqj6UXgKH72Jm0CE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568266770267993.9359327150835; Wed, 11 Sep 2019 22:39:30 -0700 (PDT) Received: from localhost ([::1]:58232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8HpF-0005Dr-2J for importer@patchew.org; Thu, 12 Sep 2019 01:39:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56543) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hmu-0003Vg-TZ for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hms-0002wg-QC for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:00 -0400 Received: from mga11.intel.com ([192.55.52.93]:18593) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hmq-0002tG-S6 for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:36:58 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:36:49 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:36:47 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030758" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:30 +0800 Message-Id: <20190912053638.4858-4-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 03/11] qapi: Add builtin type time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, jonathan.cameron@huawei.com, dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add optional builtin type time, fallback is uint64. This type use qemu_strtotime_ps() for pre-converting time suffix to numbers. Signed-off-by: Tao Xu --- No changes in v11. New patch in v10. --- include/qapi/visitor-impl.h | 4 ++++ include/qapi/visitor.h | 9 +++++++++ qapi/opts-visitor.c | 22 ++++++++++++++++++++++ qapi/qapi-visit-core.c | 12 ++++++++++++ qapi/qobject-input-visitor.c | 18 ++++++++++++++++++ qapi/trace-events | 1 + scripts/qapi/common.py | 2 ++ 7 files changed, 68 insertions(+) diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 8ccb3b6c20..e0979563c7 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -88,6 +88,10 @@ struct Visitor void (*type_size)(Visitor *v, const char *name, uint64_t *obj, Error **errp); =20 + /* Optional; fallback is type_uint64() */ + void (*type_time)(Visitor *v, const char *name, uint64_t *obj, + Error **errp); + /* Must be set */ void (*type_bool)(Visitor *v, const char *name, bool *obj, Error **err= p); =20 diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 5b2ed3f202..4c3198b1c5 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -554,6 +554,15 @@ void visit_type_int64(Visitor *v, const char *name, in= t64_t *obj, void visit_type_size(Visitor *v, const char *name, uint64_t *obj, Error **errp); =20 +/* + * Visit a uint64_t value. + * Like visit_type_uint64(), except that some visitors may choose to + * recognize numbers with timeunit suffix, such as "ps", "ns", "us" + * "ms" and "s". + */ +void visit_type_time(Visitor *v, const char *name, uint64_t *obj, + Error **errp); + /* * Visit a boolean value. * diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 324b197495..d73b2e51a0 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -508,6 +508,27 @@ opts_type_size(Visitor *v, const char *name, uint64_t = *obj, Error **errp) processed(ov, name); } =20 +static void +opts_type_time(Visitor *v, const char *name, uint64_t *obj, Error **errp) +{ + OptsVisitor *ov =3D to_ov(v); + const QemuOpt *opt; + int err; + + opt =3D lookup_scalar(ov, name, errp); + if (!opt) { + return; + } + + err =3D qemu_strtotime_ps(opt->str ? opt->str : "", NULL, obj); + if (err < 0) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, + "a time value"); + return; + } + + processed(ov, name); +} =20 static void opts_optional(Visitor *v, const char *name, bool *present) @@ -555,6 +576,7 @@ opts_visitor_new(const QemuOpts *opts) ov->visitor.type_int64 =3D &opts_type_int64; ov->visitor.type_uint64 =3D &opts_type_uint64; ov->visitor.type_size =3D &opts_type_size; + ov->visitor.type_time =3D &opts_type_time; ov->visitor.type_bool =3D &opts_type_bool; ov->visitor.type_str =3D &opts_type_str; =20 diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 5365561b07..ac8896455c 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -277,6 +277,18 @@ void visit_type_size(Visitor *v, const char *name, uin= t64_t *obj, } } =20 +void visit_type_time(Visitor *v, const char *name, uint64_t *obj, + Error **errp) +{ + assert(obj); + trace_visit_type_time(v, name, obj); + if (v->type_time) { + v->type_time(v, name, obj, errp); + } else { + v->type_uint64(v, name, obj, errp); + } +} + void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { assert(obj); diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 32236cbcb1..9b66941d8a 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -627,6 +627,23 @@ static void qobject_input_type_size_keyval(Visitor *v,= const char *name, } } =20 +static void qobject_input_type_time_keyval(Visitor *v, const char *name, + uint64_t *obj, Error **errp) +{ + QObjectInputVisitor *qiv =3D to_qiv(v); + const char *str =3D qobject_input_get_keyval(qiv, name, errp); + + if (!str) { + return; + } + + if (qemu_strtotime_ps(str, NULL, obj) < 0) { + /* TODO report -ERANGE more nicely */ + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + full_name(qiv, name), "time"); + } +} + static void qobject_input_optional(Visitor *v, const char *name, bool *pre= sent) { QObjectInputVisitor *qiv =3D to_qiv(v); @@ -708,6 +725,7 @@ Visitor *qobject_input_visitor_new_keyval(QObject *obj) v->visitor.type_any =3D qobject_input_type_any; v->visitor.type_null =3D qobject_input_type_null; v->visitor.type_size =3D qobject_input_type_size_keyval; + v->visitor.type_time =3D qobject_input_type_time_keyval; v->keyval =3D true; =20 return &v->visitor; diff --git a/qapi/trace-events b/qapi/trace-events index 5eb4afa110..c4605a7ccc 100644 --- a/qapi/trace-events +++ b/qapi/trace-events @@ -29,6 +29,7 @@ visit_type_int16(void *v, const char *name, int16_t *obj)= "v=3D%p name=3D%s obj=3D%p" visit_type_int32(void *v, const char *name, int32_t *obj) "v=3D%p name=3D%= s obj=3D%p" visit_type_int64(void *v, const char *name, int64_t *obj) "v=3D%p name=3D%= s obj=3D%p" visit_type_size(void *v, const char *name, uint64_t *obj) "v=3D%p name=3D%= s obj=3D%p" +visit_type_time(void *v, const char *name, uint64_t *obj) "v=3D%p name=3D%= s obj=3D%p" visit_type_bool(void *v, const char *name, bool *obj) "v=3D%p name=3D%s ob= j=3D%p" visit_type_str(void *v, const char *name, char **obj) "v=3D%p name=3D%s ob= j=3D%p" visit_type_number(void *v, const char *name, void *obj) "v=3D%p name=3D%s = obj=3D%p" diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index d61bfdc526..3a6f108794 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -35,6 +35,7 @@ builtin_types =3D { 'uint32': 'QTYPE_QNUM', 'uint64': 'QTYPE_QNUM', 'size': 'QTYPE_QNUM', + 'time': 'QTYPE_QNUM', 'any': None, # any QType possible, actually 'QType': 'QTYPE_QSTRING', } @@ -1834,6 +1835,7 @@ class QAPISchema(object): ('uint32', 'int', 'uint32_t'), ('uint64', 'int', 'uint64_t'), ('size', 'int', 'uint64_t'), + ('time', 'int', 'uint64_t'), ('bool', 'boolean', 'bool'), ('any', 'value', 'QObject' + pointer_suffix), ('null', 'null', 'QNull' + pointer_suffix)]: --=20 2.20.1 From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568267144; cv=none; d=zoho.com; s=zohoarc; b=H2HtzFuCYFiMHQgoGIOMmksJALkeOfMt722x2cOllnI+vjZxD9ALYncF/ve3O3x6bCSJ2jRJsRsTfudwXNRPnh6Ie5iFjY2Duc5PAjlenJea5aejv+ehx/FQzmfiWn/eNBZfMwc1XwyomSRRE5fuIfHa2N07nLvvBCwYM7Rcj+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568267144; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=yTs9njrIijdBW7fO8WZOm9vuzaaWtFoaAFZjBypru4M=; b=hU9b7wArkElptzuXUorzdgjlK+bmc6bgfoTqCLJDMr8lCtTeVw52lE46t5laBaRfkzonv5q1llxwTOIFTUiEP+ApJ4tPD4dipdmXVwz2IM+/zH2xQL4bcBfll5SWy9h5Dkqxlt8QMMKBJYbGFG/Vd48H5y00lRttEJTzZN2CFl0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568267144047542.7859505560447; Wed, 11 Sep 2019 22:45:44 -0700 (PDT) Received: from localhost ([::1]:58270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8HvC-0002wg-Uq for importer@patchew.org; Thu, 12 Sep 2019 01:45:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56544) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hmu-0003Vi-U3 for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hms-0002wl-QV for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:00 -0400 Received: from mga11.intel.com ([192.55.52.93]:18591) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hmq-0002t6-SP for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:36:58 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:36:51 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:36:49 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030764" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:31 +0800 Message-Id: <20190912053638.4858-5-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 04/11] tests: Add test for QAPI builtin type time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, jonathan.cameron@huawei.com, dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add tests for time input such as zero, around limit of precision, signed upper limit, actual upper limit, beyond limits, time suffixes, and etc. Signed-off-by: Tao Xu --- No changes in v11. New patch in v10. --- tests/test-keyval.c | 125 +++++++++++++++++++++++++++++ tests/test-qobject-input-visitor.c | 29 +++++++ 2 files changed, 154 insertions(+) diff --git a/tests/test-keyval.c b/tests/test-keyval.c index 09b0ae3c68..b36914f0fc 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -490,6 +490,130 @@ static void test_keyval_visit_size(void) visit_free(v); } =20 +static void test_keyval_visit_time(void) +{ + Error *err =3D NULL; + Visitor *v; + QDict *qdict; + uint64_t time; + + /* Lower limit zero */ + qdict =3D keyval_parse("time1=3D0", NULL, &error_abort); + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + qobject_unref(qdict); + visit_start_struct(v, NULL, NULL, 0, &error_abort); + visit_type_time(v, "time1", &time, &error_abort); + g_assert_cmpuint(time, =3D=3D, 0); + visit_check_struct(v, &error_abort); + visit_end_struct(v, NULL); + visit_free(v); + + /* Around limit of precision: 2^53-1, 2^53, 2^53+1 */ + qdict =3D keyval_parse("time1=3D9007199254740991," + "time2=3D9007199254740992," + "time3=3D9007199254740993", + NULL, &error_abort); + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + qobject_unref(qdict); + visit_start_struct(v, NULL, NULL, 0, &error_abort); + visit_type_time(v, "time1", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 0x1fffffffffffff); + visit_type_time(v, "time2", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 0x20000000000000); + visit_type_time(v, "time3", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 0x20000000000000); + visit_check_struct(v, &error_abort); + visit_end_struct(v, NULL); + visit_free(v); + + /* Close to signed upper limit 0x7ffffffffffffc00 (53 msbs set) */ + qdict =3D keyval_parse("time1=3D9223372036854774784," /* 7ffffffffffff= c00 */ + "time2=3D9223372036854775295", /* 7ffffffffffffdf= f */ + NULL, &error_abort); + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + qobject_unref(qdict); + visit_start_struct(v, NULL, NULL, 0, &error_abort); + visit_type_time(v, "time1", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 0x7ffffffffffffc00); + visit_type_time(v, "time2", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 0x7ffffffffffffc00); + visit_check_struct(v, &error_abort); + visit_end_struct(v, NULL); + visit_free(v); + + /* Close to actual upper limit 0xfffffffffffff800 (53 msbs set) */ + qdict =3D keyval_parse("time1=3D18446744073709549568," /* ffffffffffff= f800 */ + "time2=3D18446744073709550591", /* fffffffffffffb= ff */ + NULL, &error_abort); + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + qobject_unref(qdict); + visit_start_struct(v, NULL, NULL, 0, &error_abort); + visit_type_time(v, "time1", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 0xfffffffffffff800); + visit_type_time(v, "time2", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 0xfffffffffffff800); + visit_check_struct(v, &error_abort); + visit_end_struct(v, NULL); + visit_free(v); + + /* Beyond limits */ + qdict =3D keyval_parse("time1=3D-1," + "time2=3D18446744073709550592", /* fffffffffffffc= 00 */ + NULL, &error_abort); + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + qobject_unref(qdict); + visit_start_struct(v, NULL, NULL, 0, &error_abort); + visit_type_time(v, "time1", &time, &err); + error_free_or_abort(&err); + visit_type_time(v, "time2", &time, &err); + error_free_or_abort(&err); + visit_end_struct(v, NULL); + visit_free(v); + + /* Suffixes */ + qdict =3D keyval_parse("time1=3D2ps,time2=3D3.4ns,time3=3D5us," + "time4=3D0.6ms,time5=3D700s", + NULL, &error_abort); + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + qobject_unref(qdict); + visit_start_struct(v, NULL, NULL, 0, &error_abort); + visit_type_time(v, "time1", &time, &error_abort); + g_assert_cmpuint(time, =3D=3D, 2); + visit_type_time(v, "time2", &time, &error_abort); + g_assert_cmpuint(time, =3D=3D, 3400); + visit_type_time(v, "time3", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 5 * 1000 * 1000); + visit_type_time(v, "time4", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 600 * 1000 * 1000); + visit_type_time(v, "time5", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 700 * 1000000000000ULL); + visit_check_struct(v, &error_abort); + visit_end_struct(v, NULL); + visit_free(v); + + /* Beyond limit with suffix */ + qdict =3D keyval_parse("time1=3D18446745s", NULL, &error_abort); + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + qobject_unref(qdict); + visit_start_struct(v, NULL, NULL, 0, &error_abort); + visit_type_time(v, "time1", &time, &err); + error_free_or_abort(&err); + visit_end_struct(v, NULL); + visit_free(v); + + /* Trailing crap */ + qdict =3D keyval_parse("time1=3D89ks,time2=3Dns", NULL, &error_abort); + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + qobject_unref(qdict); + visit_start_struct(v, NULL, NULL, 0, &error_abort); + visit_type_time(v, "time1", &time, &err); + error_free_or_abort(&err); + visit_type_time(v, "time2", &time, &err);; + error_free_or_abort(&err); + visit_end_struct(v, NULL); + visit_free(v); +} + static void test_keyval_visit_dict(void) { Error *err =3D NULL; @@ -678,6 +802,7 @@ int main(int argc, char *argv[]) g_test_add_func("/keyval/visit/bool", test_keyval_visit_bool); g_test_add_func("/keyval/visit/number", test_keyval_visit_number); g_test_add_func("/keyval/visit/size", test_keyval_visit_size); + g_test_add_func("/keyval/visit/time", test_keyval_visit_time); g_test_add_func("/keyval/visit/dict", test_keyval_visit_dict); g_test_add_func("/keyval/visit/list", test_keyval_visit_list); g_test_add_func("/keyval/visit/optional", test_keyval_visit_optional); diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index 6bacabf063..4b5820b744 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -366,6 +366,31 @@ static void test_visitor_in_size_str_fail(TestInputVis= itorData *data, error_free_or_abort(&err); } =20 +static void test_visitor_in_time_str_keyval(TestInputVisitorData *data, + const void *unused) +{ + uint64_t res, value =3D 265 * 1000 * 1000; + Visitor *v; + + v =3D visitor_input_test_init_full(data, true, "\"265us\""); + + visit_type_time(v, NULL, &res, &error_abort); + g_assert_cmpfloat(res, =3D=3D, value); +} + +static void test_visitor_in_time_str_fail(TestInputVisitorData *data, + const void *unused) +{ + uint64_t res =3D 0; + Visitor *v; + Error *err =3D NULL; + + v =3D visitor_input_test_init(data, "\"265us\""); + + visit_type_time(v, NULL, &res, &err); + error_free_or_abort(&err); +} + static void test_visitor_in_string(TestInputVisitorData *data, const void *unused) { @@ -1311,6 +1336,10 @@ int main(int argc, char **argv) NULL, test_visitor_in_size_str_keyval); input_visitor_test_add("/visitor/input/size_str_fail", NULL, test_visitor_in_size_str_fail); + input_visitor_test_add("/visitor/input/time_str_keyval", + NULL, test_visitor_in_time_str_keyval); + input_visitor_test_add("/visitor/input/time_str_fail", + NULL, test_visitor_in_time_str_fail); input_visitor_test_add("/visitor/input/string", NULL, test_visitor_in_string); input_visitor_test_add("/visitor/input/enum", --=20 2.20.1 From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568266946; cv=none; d=zoho.com; s=zohoarc; b=kvPpQpQaHakVZdaR9CnZ0RSbG7BBldOGTsUHY/Oc7jRW3k09iPLH4TzuIBGkUrxaxT9n2le/aPAjECxWOVPGOkIgDwrcub1UapvMfyb78m6tX2eqjn6dzn+6xdLbj+a/ZFd7B0JfyjOLKgMSqR/AZWqePfEdlmqwB9H3zRGYyC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568266946; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2GVE9TC3UI+HDo3pbapXcLTG9nDtMCesPz8HHYoP8lw=; b=HubeIywRCew1VbvksHG+vriahLNmRqD0X1Zc8dIIatPEM5qJZxNRsmJEZ/N160BSHXfIvHtgX4UUhasPc3GNp8+hnQYaF1gjnaXXX2+gF00bXRJWf5+kifyXOer1AzvnsjQYnp2+9j+4nwBnUSny9XoGV+TbmMCtLf7c8otpmNk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568266946005567.962821278661; Wed, 11 Sep 2019 22:42:26 -0700 (PDT) Received: from localhost ([::1]:58254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hs8-0000Rv-Fn for importer@patchew.org; Thu, 12 Sep 2019 01:42:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56542) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hmu-0003Vf-TM for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hms-0002wb-Q1 for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:00 -0400 Received: from mga11.intel.com ([192.55.52.93]:18596) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hmq-0002tc-Sn for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:36:58 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:36:52 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:36:51 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030771" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:32 +0800 Message-Id: <20190912053638.4858-6-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 05/11] numa: Extend CLI to provide initiator information for numa nodes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, jonathan.cameron@huawei.com, dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In ACPI 6.3 chapter 5.2.27 Heterogeneous Memory Attribute Table (HMAT), The initiator represents processor which access to memory. And in 5.2.27.3 Memory Proximity Domain Attributes Structure, the attached initiator is defined as where the memory controller responsible for a memory proximity domain. With attached initiator information, the topology of heterogeneous memory can be described. Extend CLI of "-numa node" option to indicate the initiator numa node-id. In the linux kernel, the codes in drivers/acpi/hmat/hmat.c parse and report the platform's HMAT tables. Suggested-by: Dan Williams Signed-off-by: Tao Xu Reviewed-by: Jingqi Liu --- No changes in v11. Changes in v10: - Add machine oprion properties "-machine hmat=3Don|off" for enabling or disabling HMAT in QEMU. - Add more description for initiator option. - Report error then HMAT is enalbe and initiator option is missing. Not allow invaild initiator now. (Igor) --- hw/core/machine.c | 72 +++++++++++++++++++++++++++++++++++++++++++ hw/core/numa.c | 11 +++++++ include/sysemu/numa.h | 6 ++++ qapi/machine.json | 10 +++++- qemu-options.hx | 35 ++++++++++++++++++--- 5 files changed, 128 insertions(+), 6 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 1689ad3bf8..b42f574282 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -518,6 +518,20 @@ static void machine_set_nvdimm(Object *obj, bool value= , Error **errp) ms->nvdimms_state->is_enabled =3D value; } =20 +static bool machine_get_hmat(Object *obj, Error **errp) +{ + MachineState *ms =3D MACHINE(obj); + + return ms->numa_state->hmat_enabled; +} + +static void machine_set_hmat(Object *obj, bool value, Error **errp) +{ + MachineState *ms =3D MACHINE(obj); + + ms->numa_state->hmat_enabled =3D value; +} + static char *machine_get_nvdimm_persistence(Object *obj, Error **errp) { MachineState *ms =3D MACHINE(obj); @@ -645,6 +659,7 @@ void machine_set_cpu_numa_node(MachineState *machine, const CpuInstanceProperties *props, Error *= *errp) { MachineClass *mc =3D MACHINE_GET_CLASS(machine); + NodeInfo *numa_info =3D machine->numa_state->nodes; bool match =3D false; int i; =20 @@ -714,6 +729,16 @@ void machine_set_cpu_numa_node(MachineState *machine, match =3D true; slot->props.node_id =3D props->node_id; slot->props.has_node_id =3D props->has_node_id; + + if (numa_info[props->node_id].initiator_valid && + (props->node_id !=3D numa_info[props->node_id].initiator)) { + error_setg(errp, "The initiator of CPU NUMA node %" PRId64 + " should be itself.", props->node_id); + return; + } + numa_info[props->node_id].initiator_valid =3D true; + numa_info[props->node_id].has_cpu =3D true; + numa_info[props->node_id].initiator =3D props->node_id; } =20 if (!match) { @@ -960,6 +985,13 @@ static void machine_initfn(Object *obj) =20 if (mc->numa_mem_supported) { ms->numa_state =3D g_new0(NumaState, 1); + object_property_add_bool(obj, "hmat", + machine_get_hmat, machine_set_hmat, + &error_abort); + object_property_set_description(obj, "hmat", + "Set on/off to enable/disable " + "ACPI Heterogeneous Memory Attribu= te " + "Table (HMAT)", NULL); } =20 /* Register notifier when init is done for sysbus sanity checks */ @@ -1048,6 +1080,41 @@ static char *cpu_slot_to_string(const CPUArchId *cpu) return g_string_free(s, false); } =20 +static void numa_validate_initiator(NumaState *nstat) +{ + int i; + NodeInfo *numa_info =3D nstat->nodes; + + for (i =3D 0; i < nstat->num_nodes; i++) { + if (numa_info[i].initiator >=3D MAX_NODES) { + error_report("The initiator id %" PRIu16 " expects an integer " + "between 0 and %d", numa_info[i].initiator, + MAX_NODES - 1); + goto err; + } + + if (!numa_info[numa_info[i].initiator].present) { + error_report("NUMA node %" PRIu16 " is missing, use " + "'-numa node' option to declare it first.", + numa_info[i].initiator); + goto err; + } + + if (numa_info[numa_info[i].initiator].has_cpu) { + numa_info[i].initiator_valid =3D true; + } else { + error_report("The initiator of NUMA node %d is invalid.", i); + goto err; + } + } + + return; + +err: + error_printf("\n"); + exit(1); +} + static void machine_numa_finish_cpu_init(MachineState *machine) { int i; @@ -1088,6 +1155,11 @@ static void machine_numa_finish_cpu_init(MachineStat= e *machine) machine_set_cpu_numa_node(machine, &props, &error_fatal); } } + + if (machine->numa_state->hmat_enabled) { + numa_validate_initiator(machine->numa_state); + } + if (s->len && !qtest_enabled()) { warn_report("CPU(s) not present in any NUMA nodes: %s", s->str); diff --git a/hw/core/numa.c b/hw/core/numa.c index 4dfec5c95b..bdce7d4217 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -133,6 +133,17 @@ static void parse_numa_node(MachineState *ms, NumaNode= Options *node, numa_info[nodenr].node_mem =3D object_property_get_uint(o, "size",= NULL); numa_info[nodenr].node_memdev =3D MEMORY_BACKEND(o); } + + if (node->has_initiator) { + if (!ms->numa_state->hmat_enabled) { + error_setg(errp, "ACPI Heterogeneous Memory Attribute Table " + "(HMAT) is disabled, use -machine hmat=3Don before " + "set initiator of NUMA"); + return; + } + + numa_info[nodenr].initiator =3D node->initiator; + } numa_info[nodenr].present =3D true; max_numa_nodeid =3D MAX(max_numa_nodeid, nodenr + 1); ms->numa_state->num_nodes++; diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h index ae9c41d02b..a788c3b126 100644 --- a/include/sysemu/numa.h +++ b/include/sysemu/numa.h @@ -18,6 +18,9 @@ struct NodeInfo { uint64_t node_mem; struct HostMemoryBackend *node_memdev; bool present; + bool has_cpu; + bool initiator_valid; + uint16_t initiator; uint8_t distance[MAX_NODES]; }; =20 @@ -33,6 +36,9 @@ struct NumaState { /* Allow setting NUMA distance for different NUMA nodes */ bool have_numa_distance; =20 + /* Detect if HMAT support is enabled. */ + bool hmat_enabled; + /* NUMA nodes information */ NodeInfo nodes[MAX_NODES]; }; diff --git a/qapi/machine.json b/qapi/machine.json index ca26779f1a..3c2914cd1c 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -463,6 +463,13 @@ # @memdev: memory backend object. If specified for one node, # it must be specified for all nodes. # +# @initiator: defined in ACPI 6.3 Chapter 5.2.27.3 Table 5-145, +# indicate the nodeid which has the memory controller +# responsible for this NUMA node. This field provides +# additional information as to the initiator node that +# is closest (as in directly attached) to this node, and +# therefore has the best performance (since 4.2) +# # Since: 2.1 ## { 'struct': 'NumaNodeOptions', @@ -470,7 +477,8 @@ '*nodeid': 'uint16', '*cpus': ['uint16'], '*mem': 'size', - '*memdev': 'str' }} + '*memdev': 'str', + '*initiator': 'uint16' }} =20 ## # @NumaDistOptions: diff --git a/qemu-options.hx b/qemu-options.hx index bbfd936d29..74ccc4d782 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -43,7 +43,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " suppress-vmdesc=3Don|off disables self-describing mig= ration (default=3Doff)\n" " nvdimm=3Don|off controls NVDIMM support (default=3Dof= f)\n" " enforce-config-section=3Don|off enforce configuration= section migration (default=3Doff)\n" - " memory-encryption=3D@var{} memory encryption object t= o use (default=3Dnone)\n", + " memory-encryption=3D@var{} memory encryption object t= o use (default=3Dnone)\n" + " hmat=3Don|off controls ACPI HMAT support (default=3Do= ff)\n", QEMU_ARCH_ALL) STEXI @item -machine [type=3D]@var{name}[,prop=3D@var{value}[,...]] @@ -103,6 +104,9 @@ NOTE: this parameter is deprecated. Please use @option{= -global} @option{migration.send-configuration}=3D@var{on|off} instead. @item memory-encryption=3D@var{} Memory encryption object to use. The default is none. +@item hmat=3Don|off +Enables or disables ACPI Heterogeneous Memory Attribute Table (HMAT) suppo= rt. +The default is off. @end table ETEXI =20 @@ -161,14 +165,14 @@ If any on the three values is given, the total number= of CPUs @var{n} can be omi ETEXI =20 DEF("numa", HAS_ARG, QEMU_OPTION_numa, - "-numa node[,mem=3Dsize][,cpus=3Dfirstcpu[-lastcpu]][,nodeid=3Dnode]\n" - "-numa node[,memdev=3Did][,cpus=3Dfirstcpu[-lastcpu]][,nodeid=3Dnode]\= n" + "-numa node[,mem=3Dsize][,cpus=3Dfirstcpu[-lastcpu]][,nodeid=3Dnode][,= initiator=3Dnode]\n" + "-numa node[,memdev=3Did][,cpus=3Dfirstcpu[-lastcpu]][,nodeid=3Dnode][= ,initiator=3Dnode]\n" "-numa dist,src=3Dsource,dst=3Ddestination,val=3Ddistance\n" "-numa cpu,node-id=3Dnode[,socket-id=3Dx][,core-id=3Dy][,thread-id=3Dz= ]\n", QEMU_ARCH_ALL) STEXI -@item -numa node[,mem=3D@var{size}][,cpus=3D@var{firstcpu}[-@var{lastcpu}]= ][,nodeid=3D@var{node}] -@itemx -numa node[,memdev=3D@var{id}][,cpus=3D@var{firstcpu}[-@var{lastcpu= }]][,nodeid=3D@var{node}] +@item -numa node[,mem=3D@var{size}][,cpus=3D@var{firstcpu}[-@var{lastcpu}]= ][,nodeid=3D@var{node}][,initiator=3D@var{initiator}] +@itemx -numa node[,memdev=3D@var{id}][,cpus=3D@var{firstcpu}[-@var{lastcpu= }]][,nodeid=3D@var{node}][,initiator=3D@var{initiator}] @itemx -numa dist,src=3D@var{source},dst=3D@var{destination},val=3D@var{di= stance} @itemx -numa cpu,node-id=3D@var{node}[,socket-id=3D@var{x}][,core-id=3D@va= r{y}][,thread-id=3D@var{z}] @findex -numa @@ -215,6 +219,27 @@ split equally between them. @samp{mem} and @samp{memdev} are mutually exclusive. Furthermore, if one node uses @samp{memdev}, all of them have to use it. =20 +@samp{initiator} is an additional option indicate the @var{initiator} +NUMA that has best performance (the lowest latency or largest bandwidth) +to this NUMA @var{node}. Note that this option can be set only when +the machine oprion properties "-machine hmat=3Don". + +Following example creates a machine with 2 NUMA nodes, node 0 has CPU. +node 1 has only memory, and its' initiator is node 0. Note that because +node 0 has CPU, by default the initiator of node 0 is itself and must be +itself. +@example +-machine hmat=3Don \ +-m 2G,slots=3D2,maxmem=3D4G \ +-object memory-backend-ram,size=3D1G,id=3Dm0 \ +-object memory-backend-ram,size=3D1G,id=3Dm1 \ +-numa node,nodeid=3D0,memdev=3Dm0 \ +-numa node,nodeid=3D1,memdev=3Dm1,initiator=3D0 \ +-smp 2,sockets=3D2,maxcpus=3D2 \ +-numa cpu,node-id=3D0,socket-id=3D0 \ +-numa cpu,node-id=3D0,socket-id=3D1 +@end example + @var{source} and @var{destination} are NUMA node IDs. @var{distance} is the NUMA distance from @var{source} to @var{destination}. The distance from a node to itself is always 10. If any pair of nodes is --=20 2.20.1 From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568267384; cv=none; d=zoho.com; s=zohoarc; b=FOccXfKT7KIUtuh3+buc2UGp2V+0yOqF6gu5W5oyCeyghG0/JsKKgLDKWwHdnobL2+oTZy5knbsqw8xMS3K+URLQcSuDC6VA5Gy/l40Ar6UkwmTwfUIHeBJYGJj/Q/dNJ5vRLPND5hgllgyH8nSikAeJ9yR7zPheEylr06RiPKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568267384; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=mgPcRVEarBhUxufcSOyN6AJHgjmVu+mj7t7jwZJu59M=; b=ZCxAuldGarA29P+dt8cNtHVdaxjiigzOruqgOSqYgl9+DB+EpWgQx7UPZeZBKUas6pcvhRGzS10DrSj4BKur+pkQlEQIe5Pf55FnnuRKmLbWuBb6HzMtWsZNPgkWw5PVEqK9mqj3bLQdWX9n1aXO/Zr910rIvX9YgqLZ+7Td9XE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568267384886573.6740856918772; Wed, 11 Sep 2019 22:49:44 -0700 (PDT) Received: from localhost ([::1]:58308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8HzD-0006Yq-JE for importer@patchew.org; Thu, 12 Sep 2019 01:49:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56596) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hmx-0003Xt-HY for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hmu-0002yp-QM for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:03 -0400 Received: from mga11.intel.com ([192.55.52.93]:18596) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hmt-0002tc-1y for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:36:59 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:36:54 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:36:53 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030779" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:33 +0800 Message-Id: <20190912053638.4858-7-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 06/11] numa: Extend CLI to provide memory latency and bandwidth information X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, jonathan.cameron@huawei.com, dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Liu Jingqi Add -numa hmat-lb option to provide System Locality Latency and Bandwidth Information. These memory attributes help to build System Locality Latency and Bandwidth Information Structure(s) in ACPI Heterogeneous Memory Attribute Table (HMAT). Signed-off-by: Liu Jingqi Signed-off-by: Tao Xu --- Changes in v11: - Move numa option patches forward. - Add num_initiator in Numa_state to record the number of initiators. - Simplify struct HMAT_LB_Info, use uint64_t array to store data. - Drop hmat_get_base(). Changes in v10: - use new builtin type 'time' as qapi input. --- hw/core/numa.c | 114 ++++++++++++++++++++++++++++++++++++++++++ include/sysemu/numa.h | 44 ++++++++++++++++ qapi/machine.json | 95 ++++++++++++++++++++++++++++++++++- qemu-options.hx | 49 +++++++++++++++++- 4 files changed, 299 insertions(+), 3 deletions(-) diff --git a/hw/core/numa.c b/hw/core/numa.c index bdce7d4217..82322734e3 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -186,6 +186,100 @@ void parse_numa_distance(MachineState *ms, NumaDistOp= tions *dist, Error **errp) ms->numa_state->have_numa_distance =3D true; } =20 +void parse_numa_hmat_lb(NumaState *nstat, NumaHmatLBOptions *node, + Error **errp) +{ + int i; + int init =3D node->initiator; + int targ =3D node->target; + int nb_nodes =3D nstat->num_nodes; + NodeInfo *numa_info =3D nstat->nodes; + HMAT_LB_Info *hmat_lb =3D nstat->hmat_lb[node->hierarchy][node->data_t= ype]; + + /* Error checking */ + if (init >=3D nb_nodes) { + error_setg(errp, "Invalid initiator=3D%d, it should be less than %= d.", + init, nb_nodes); + return; + } + if (targ >=3D nb_nodes) { + error_setg(errp, "Invalid target=3D%d, it should be less than %d.", + targ, nb_nodes); + return; + } + if (!numa_info[init].has_cpu) { + error_setg(errp, "Invalid initiator=3D%d, it isn't an " + "initiator proximity domain.", init); + return; + } + if (!numa_info[targ].present) { + error_setg(errp, "Invalid target=3D%d, it hasn't a valid NUMA node= .", + targ); + return; + } + + /* HMAT latency and bandwidth data initialization */ + if (nstat->num_initiator =3D=3D 0) { + for (i =3D 0; i < nstat->num_nodes; i++) { + if (numa_info[i].has_cpu) { + nstat->num_initiator++; + } + } + } + + if (!hmat_lb) { + int size =3D nstat->num_initiator * nb_nodes * sizeof(uint64_t); + hmat_lb =3D g_malloc0(sizeof(*hmat_lb)); + nstat->hmat_lb[node->hierarchy][node->data_type] =3D hmat_lb; + hmat_lb->latency =3D g_malloc0(size); + hmat_lb->bandwidth =3D g_malloc0(size); + } + hmat_lb->hierarchy =3D node->hierarchy; + hmat_lb->data_type =3D node->data_type; + + /* Input latency data */ + if (node->data_type <=3D HMATLB_DATA_TYPE_WRITE_LATENCY) { + if (!node->has_latency) { + error_setg(errp, "Missing 'latency' option."); + return; + } + if (node->has_bandwidth) { + error_setg(errp, "Invalid option 'bandwidth' since " + "the data type is latency."); + return; + } + if (hmat_lb->latency[init * nb_nodes + targ]) { + error_setg(errp, "Duplicate configuration of the latency for " + "initiator=3D%d and target=3D%d.", init, targ); + return; + } + + hmat_lb->latency[init * nb_nodes + targ] =3D node->latency; + } + + /* Input bandwidth data */ + if (node->data_type >=3D HMATLB_DATA_TYPE_ACCESS_BANDWIDTH) { + if (!node->has_bandwidth) { + error_setg(errp, "Missing 'bandwidth' option."); + return; + } + if (node->has_latency) { + error_setg(errp, "Invalid option 'latency' since " + "the data type is bandwidth."); + return; + } + if (hmat_lb->bandwidth[init * nb_nodes + targ]) { + error_setg(errp, "Duplicate configuration of the bandwidth for= " + "initiator=3D%d and target=3D%d.", init, targ); + return; + } + + /* Convert Byte to Megabyte */ + hmat_lb->bandwidth[init * nb_nodes + targ] =3D + node->bandwidth / 1024 / 1024; + } +} + void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp) { Error *err =3D NULL; @@ -224,6 +318,19 @@ void set_numa_options(MachineState *ms, NumaOptions *o= bject, Error **errp) machine_set_cpu_numa_node(ms, qapi_NumaCpuOptions_base(&object->u.= cpu), &err); break; + case NUMA_OPTIONS_TYPE_HMAT_LB: + if (!ms->numa_state->hmat_enabled) { + error_setg(errp, "ACPI Heterogeneous Memory Attribute Table " + "(HMAT) is disabled, use -machine hmat=3Don before " + "set initiator of NUMA"); + return; + } + + parse_numa_hmat_lb(ms->numa_state, &object->u.hmat_lb, &err); + if (err) { + goto end; + } + break; default: abort(); } @@ -251,6 +358,13 @@ static int parse_numa(void *opaque, QemuOpts *opts, Er= ror **errp) qemu_strtosz_MiB(mem_str, NULL, &object->u.node.mem); } =20 + /* Set up suffix-less bandwidth as megabytes */ + if ((object->type =3D=3D NUMA_OPTIONS_TYPE_HMAT_LB) && + object->u.hmat_lb.has_bandwidth) { + const char *bw_str =3D qemu_opt_get(opts, "bandwidth"); + qemu_strtosz_MiB(bw_str, NULL, &object->u.hmat_lb.bandwidth); + } + set_numa_options(ms, object, &err); =20 end: diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h index a788c3b126..876beaee22 100644 --- a/include/sysemu/numa.h +++ b/include/sysemu/numa.h @@ -14,6 +14,27 @@ struct CPUArchId; #define NUMA_DISTANCE_MAX 254 #define NUMA_DISTANCE_UNREACHABLE 255 =20 +/* the value of AcpiHmatLBInfo flags */ +enum { + HMAT_LB_MEM_MEMORY =3D 0, + HMAT_LB_MEM_CACHE_1ST_LEVEL =3D 1, + HMAT_LB_MEM_CACHE_2ND_LEVEL =3D 2, + HMAT_LB_MEM_CACHE_3RD_LEVEL =3D 3, +}; + +/* the value of AcpiHmatLBInfo data type */ +enum { + HMAT_LB_DATA_ACCESS_LATENCY =3D 0, + HMAT_LB_DATA_READ_LATENCY =3D 1, + HMAT_LB_DATA_WRITE_LATENCY =3D 2, + HMAT_LB_DATA_ACCESS_BANDWIDTH =3D 3, + HMAT_LB_DATA_READ_BANDWIDTH =3D 4, + HMAT_LB_DATA_WRITE_BANDWIDTH =3D 5, +}; + +#define HMAT_LB_LEVELS (HMAT_LB_MEM_CACHE_3RD_LEVEL + 1) +#define HMAT_LB_TYPES (HMAT_LB_DATA_WRITE_BANDWIDTH + 1) + struct NodeInfo { uint64_t node_mem; struct HostMemoryBackend *node_memdev; @@ -29,6 +50,21 @@ struct NumaNodeMem { uint64_t node_plugged_mem; }; =20 +struct HMAT_LB_Info { + /* Indicates it's memory or the specified level memory side cache. */ + uint8_t hierarchy; + + /* Present the type of data, access/read/write latency or bandwidth. */ + uint8_t data_type; + + /* Array to store the latencies */ + uint64_t *latency; + + /* Array to store the bandwidthes */ + uint64_t *bandwidth; +}; +typedef struct HMAT_LB_Info HMAT_LB_Info; + struct NumaState { /* Number of NUMA nodes */ int num_nodes; @@ -39,13 +75,21 @@ struct NumaState { /* Detect if HMAT support is enabled. */ bool hmat_enabled; =20 + /* Number of Proximity Domains that can initiate memory access request= s. */ + int num_initiator; + /* NUMA nodes information */ NodeInfo nodes[MAX_NODES]; + + /* NUMA nodes HMAT Locality Latency and Bandwidth Information */ + HMAT_LB_Info *hmat_lb[HMAT_LB_LEVELS][HMAT_LB_TYPES]; }; typedef struct NumaState NumaState; =20 void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp); void parse_numa_opts(MachineState *ms); +void parse_numa_hmat_lb(NumaState *nstat, NumaHmatLBOptions *node, + Error **errp); void numa_complete_configuration(MachineState *ms); void query_numa_node_mem(NumaNodeMem node_mem[], MachineState *ms); extern QemuOptsList qemu_numa_opts; diff --git a/qapi/machine.json b/qapi/machine.json index 3c2914cd1c..b6019335e8 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -426,10 +426,12 @@ # # @cpu: property based CPU(s) to node mapping (Since: 2.10) # +# @hmat-lb: memory latency and bandwidth information (Since: 4.2) +# # Since: 2.1 ## { 'enum': 'NumaOptionsType', - 'data': [ 'node', 'dist', 'cpu' ] } + 'data': [ 'node', 'dist', 'cpu', 'hmat-lb' ] } =20 ## # @NumaOptions: @@ -444,7 +446,8 @@ 'data': { 'node': 'NumaNodeOptions', 'dist': 'NumaDistOptions', - 'cpu': 'NumaCpuOptions' }} + 'cpu': 'NumaCpuOptions', + 'hmat-lb': 'NumaHmatLBOptions' }} =20 ## # @NumaNodeOptions: @@ -557,6 +560,94 @@ 'base': 'CpuInstanceProperties', 'data' : {} } =20 +## +# @HmatLBMemoryHierarchy: +# +# The memory hierarchy in the System Locality Latency +# and Bandwidth Information Structure of HMAT (Heterogeneous +# Memory Attribute Table) +# +# For more information of @HmatLBMemoryHierarchy see +# the chapter 5.2.27.4: Table 5-142: Field "Flags" of ACPI 6.3 spec. +# +# @memory: the structure represents the memory performance +# +# @first-level: first level memory of memory side cached memory +# +# @second-level: second level memory of memory side cached memory +# +# @third-level: third level memory of memory side cached memory +# +# Since: 4.2 +## +{ 'enum': 'HmatLBMemoryHierarchy', + 'data': [ 'memory', 'first-level', 'second-level', 'third-level' ] } + +## +# @HmatLBDataType: +# +# Data type in the System Locality Latency +# and Bandwidth Information Structure of HMAT (Heterogeneous +# Memory Attribute Table) +# +# For more information of @HmatLBDataType see +# the chapter 5.2.27.4: Table 5-142: Field "Data Type" of ACPI 6.3 spec. +# +# @access-latency: access latency (nanoseconds) +# +# @read-latency: read latency (nanoseconds) +# +# @write-latency: write latency (nanoseconds) +# +# @access-bandwidth: access bandwidth (MB/s) +# +# @read-bandwidth: read bandwidth (MB/s) +# +# @write-bandwidth: write bandwidth (MB/s) +# +# Since: 4.2 +## +{ 'enum': 'HmatLBDataType', + 'data': [ 'access-latency', 'read-latency', 'write-latency', + 'access-bandwidth', 'read-bandwidth', 'write-bandwidth' ] } + +## +# @NumaHmatLBOptions: +# +# Set the system locality latency and bandwidth information +# between Initiator and Target proximity Domains. +# +# For more information of @NumaHmatLBOptions see +# the chapter 5.2.27.4: Table 5-142 of ACPI 6.3 spec. +# +# @initiator: the Initiator Proximity Domain. +# +# @target: the Target Proximity Domain. +# +# @hierarchy: the Memory Hierarchy. Indicates the performance +# of memory or side cache. +# +# @data-type: presents the type of data, access/read/write +# latency or hit latency. +# +# @latency: the value of latency from @initiator to @target proximity doma= in, +# the latency units are "ps(picosecond)", "ns(nanosecond)" or +# "us(microsecond)". +# +# @bandwidth: the value of bandwidth between @initiator and @target proxim= ity +# domain, the bandwidth units are "MB(/s)","GB(/s)" or "TB(/s)= ". +# +# Since: 4.2 +## +{ 'struct': 'NumaHmatLBOptions', + 'data': { + 'initiator': 'uint16', + 'target': 'uint16', + 'hierarchy': 'HmatLBMemoryHierarchy', + 'data-type': 'HmatLBDataType', + '*latency': 'time', + '*bandwidth': 'size' }} + ## # @HostMemPolicy: # diff --git a/qemu-options.hx b/qemu-options.hx index 74ccc4d782..129da0cdc3 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -168,16 +168,19 @@ DEF("numa", HAS_ARG, QEMU_OPTION_numa, "-numa node[,mem=3Dsize][,cpus=3Dfirstcpu[-lastcpu]][,nodeid=3Dnode][,= initiator=3Dnode]\n" "-numa node[,memdev=3Did][,cpus=3Dfirstcpu[-lastcpu]][,nodeid=3Dnode][= ,initiator=3Dnode]\n" "-numa dist,src=3Dsource,dst=3Ddestination,val=3Ddistance\n" - "-numa cpu,node-id=3Dnode[,socket-id=3Dx][,core-id=3Dy][,thread-id=3Dz= ]\n", + "-numa cpu,node-id=3Dnode[,socket-id=3Dx][,core-id=3Dy][,thread-id=3Dz= ]\n" + "-numa hmat-lb,initiator=3Dnode,target=3Dnode,hierarchy=3Dmemory|first= -level|second-level|third-level,data-type=3Daccess-latency|read-latency|wri= te-latency[,latency=3Dlat][,bandwidth=3Dbw]\n", QEMU_ARCH_ALL) STEXI @item -numa node[,mem=3D@var{size}][,cpus=3D@var{firstcpu}[-@var{lastcpu}]= ][,nodeid=3D@var{node}][,initiator=3D@var{initiator}] @itemx -numa node[,memdev=3D@var{id}][,cpus=3D@var{firstcpu}[-@var{lastcpu= }]][,nodeid=3D@var{node}][,initiator=3D@var{initiator}] @itemx -numa dist,src=3D@var{source},dst=3D@var{destination},val=3D@var{di= stance} @itemx -numa cpu,node-id=3D@var{node}[,socket-id=3D@var{x}][,core-id=3D@va= r{y}][,thread-id=3D@var{z}] +@itemx -numa hmat-lb,initiator=3D@var{node},target=3D@var{node},hierarchy= =3D@var{str},data-type=3D@var{str}[,latency=3D@var{lat}][,bandwidth=3D@var{= bw}] @findex -numa Define a NUMA node and assign RAM and VCPUs to it. Set the NUMA distance from a source node to a destination node. +Set the ACPI Heterogeneous Memory Attributes for the given nodes. =20 Legacy VCPU assignment uses @samp{cpus} option where @var{firstcpu} and @var{lastcpu} are CPU indexes. Each @@ -256,6 +259,50 @@ specified resources, it just assigns existing resource= s to NUMA nodes. This means that one still has to use the @option{-m}, @option{-smp} options to allocate RAM and VCPUs respectively. =20 +Use @samp{hmat-lb} to set System Locality Latency and Bandwidth Information +between initiator and target NUMA nodes in ACPI Heterogeneous Attribute Me= mory Table (HMAT). +Initiator NUMA node can create memory requests, usually including one or m= ore processors. +Target NUMA node contains addressable memory. + +In @samp{hmat-lb} option, @var{node} are NUMA node IDs. @var{str} of 'hier= archy' +is the memory hierarchy of the target NUMA node: if @var{str} is 'memory',= the structure +represents the memory performance; if @var{str} is 'first-level|second-lev= el|third-level', +this structure represents aggregated performance of memory side caches for= each domain. +@var{str} of 'data-type' is type of data represented by this structure ins= tance: +if 'hierarchy' is 'memory', 'data-type' is 'access|read|write' latency(nan= oseconds) +or 'access|read|write' bandwidth(MB/s) of the target memory; if 'hierarchy= ' is +'first-level|second-level|third-level', 'data-type' is 'access|read|write'= hit latency +or 'access|read|write' hit bandwidth of the target memory side cache. + +@var{lat} of 'latency' is latency value, the possible value and units are +NUM[ps|ns|us] (picosecond|nanosecond|microsecond), the recommended unit is= 'ns'. @var{bw} +is bandwidth value, the possible value and units are NUM[M|G|T], mean that +the bandwidth value are NUM MB/s, GB/s or TB/s. Note that max NUM is 65534, +if NUM is 0, means the corresponding latency or bandwidth information is n= ot provided. +And if input numbers without any unit, the latency unit will be 'ps' and t= he bandwidth +will be MB/s. + +For example, the following option assigns NUMA node 0 and 1. Node 0 has 2 = cpus and +a ram, node 1 has only a ram. The processors in node 0 access memory in no= de +0 with access-latency 5 nanoseconds, access-bandwidth is 200 MB/s; +The processors in NUMA node 0 access memory in NUMA node 1 with access-lat= ency 10 +nanoseconds, access-bandwidth is 100 MB/s. +@example +-machine hmat=3Don \ +-m 2G \ +-object memory-backend-ram,size=3D1G,id=3Dm0 \ +-object memory-backend-ram,size=3D1G,id=3Dm1 \ +-smp 2 \ +-numa node,nodeid=3D0,memdev=3Dm0 \ +-numa node,nodeid=3D1,memdev=3Dm1,initiator=3D0 \ +-numa cpu,node-id=3D0,socket-id=3D0 \ +-numa cpu,node-id=3D0,socket-id=3D1 \ +-numa hmat-lb,initiator=3D0,target=3D0,hierarchy=3Dmemory,data-type=3Dacce= ss-latency,latency=3D5ns \ +-numa hmat-lb,initiator=3D0,target=3D0,hierarchy=3Dmemory,data-type=3Dacce= ss-bandwidth,bandwidth=3D200M \ +-numa hmat-lb,initiator=3D0,target=3D1,hierarchy=3Dmemory,data-type=3Dacce= ss-latency,latency=3D10ns \ +-numa hmat-lb,initiator=3D0,target=3D1,hierarchy=3Dmemory,data-type=3Dacce= ss-bandwidth,bandwidth=3D100M +@end example + ETEXI =20 DEF("add-fd", HAS_ARG, QEMU_OPTION_add_fd, --=20 2.20.1 From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568267253; cv=none; d=zoho.com; s=zohoarc; b=aVMH2G7q8tXRQHaPsj2wrGbQ2JJxxKqGWhC0+/cLAahNUovfPJ8nDsMj5UcqnwsUVIuCIxOMXeIjGxCro3iMdQPO25jUe59lKBEjERL2fIJoaikClo4Fp2tn0Z74MdmCVXQNnl8ZHzv7xIDZC52vQb8YQvveol/VCeUWiHtES5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568267253; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=0xPa3jLSxbCrTZLx75EOaKnLFyu+2ELKHOz+3qGmLA8=; b=F85Cdm0+Ccx0KuTmpivhiSwuEb3r2agVNTndKhEDjIsdrK0XSey7URNBB6BC1snq76blSaYjQSWZvEodTNl0N0V5ZDY+iM6YswPmDTaSZPL7nQNmcwXOMrN62+c0INWMxhiAGW5BvTroWHXXfP2pCnXHyTcnscmiqcdGc+ngHeg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568267253535262.2262715085533; Wed, 11 Sep 2019 22:47:33 -0700 (PDT) Received: from localhost ([::1]:58290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hx6-0004nH-Bv for importer@patchew.org; Thu, 12 Sep 2019 01:47:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56555) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hmv-0003W0-Io for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hmt-0002ws-DM for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:01 -0400 Received: from mga11.intel.com ([192.55.52.93]:18593) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hmt-0002tG-1C for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:36:59 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:36:57 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:36:55 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030788" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:34 +0800 Message-Id: <20190912053638.4858-8-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 07/11] numa: Extend CLI to provide memory side cache information X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, Daniel Black , jonathan.cameron@huawei.com, dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Liu Jingqi Add -numa hmat-cache option to provide Memory Side Cache Information. These memory attributes help to build Memory Side Cache Information Structure(s) in ACPI Heterogeneous Memory Attribute Table (HMAT). Reviewed-by: Daniel Black Signed-off-by: Liu Jingqi Signed-off-by: Tao Xu --- Changes in v11: - Move numa option patches forward. --- hw/core/numa.c | 74 +++++++++++++++++++++++++++++++++++++++ include/sysemu/numa.h | 31 +++++++++++++++++ qapi/machine.json | 81 +++++++++++++++++++++++++++++++++++++++++-- qemu-options.hx | 16 +++++++-- 4 files changed, 198 insertions(+), 4 deletions(-) diff --git a/hw/core/numa.c b/hw/core/numa.c index 82322734e3..6b8ed8b8c8 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -280,6 +280,67 @@ void parse_numa_hmat_lb(NumaState *nstat, NumaHmatLBOp= tions *node, } } =20 +void parse_numa_hmat_cache(MachineState *ms, NumaHmatCacheOptions *node, + Error **errp) +{ + int nb_numa_nodes =3D ms->numa_state->num_nodes; + HMAT_Cache_Info *hmat_cache =3D NULL; + + if (node->node_id >=3D nb_numa_nodes) { + error_setg(errp, "Invalid node-id=3D%" PRIu32 + ", it should be less than %d.", + node->node_id, nb_numa_nodes); + return; + } + + if (node->total > MAX_HMAT_CACHE_LEVEL) { + error_setg(errp, "Invalid total=3D%" PRIu8 + ", it should be less than or equal to %d.", + node->total, MAX_HMAT_CACHE_LEVEL); + return; + } + if (node->level > node->total) { + error_setg(errp, "Invalid level=3D%" PRIu8 + ", it should be less than or equal to" + " total=3D%" PRIu8 ".", + node->level, node->total); + return; + } + if (ms->numa_state->hmat_cache[node->node_id][node->level]) { + error_setg(errp, "Duplicate configuration of the side cache for " + "node-id=3D%" PRIu32 " and level=3D%" PRIu8 ".", + node->node_id, node->level); + return; + } + + if ((node->level > 1) && + ms->numa_state->hmat_cache[node->node_id][node->level - 1] && + (node->size >=3D + ms->numa_state->hmat_cache[node->node_id][node->level - 1]->si= ze)) { + error_setg(errp, "Invalid size=3D0x%" PRIx64 + ", the size of level=3D%" PRIu8 + " should be less than the size(0x%" PRIx64 + ") of level=3D%" PRIu8 ".", + node->size, node->level, + ms->numa_state->hmat_cache[node->node_id] + [node->level - 1]->size, + node->level - 1); + return; + } + + hmat_cache =3D g_malloc0(sizeof(*hmat_cache)); + + hmat_cache->mem_proximity =3D node->node_id; + hmat_cache->size =3D node->size; + hmat_cache->total_levels =3D node->total; + hmat_cache->level =3D node->level; + hmat_cache->associativity =3D node->assoc; + hmat_cache->write_policy =3D node->policy; + hmat_cache->line_size =3D node->line; + + ms->numa_state->hmat_cache[node->node_id][node->level] =3D hmat_cache; +} + void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp) { Error *err =3D NULL; @@ -331,6 +392,19 @@ void set_numa_options(MachineState *ms, NumaOptions *o= bject, Error **errp) goto end; } break; + case NUMA_OPTIONS_TYPE_HMAT_CACHE: + if (!ms->numa_state->hmat_enabled) { + error_setg(errp, "ACPI Heterogeneous Memory Attribute Table " + "(HMAT) is disabled, use -machine hmat=3Don before " + "set initiator of NUMA"); + return; + } + + parse_numa_hmat_cache(ms, &object->u.hmat_cache, &err); + if (err) { + goto end; + } + break; default: abort(); } diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h index 876beaee22..39312eefd4 100644 --- a/include/sysemu/numa.h +++ b/include/sysemu/numa.h @@ -35,6 +35,8 @@ enum { #define HMAT_LB_LEVELS (HMAT_LB_MEM_CACHE_3RD_LEVEL + 1) #define HMAT_LB_TYPES (HMAT_LB_DATA_WRITE_BANDWIDTH + 1) =20 +#define MAX_HMAT_CACHE_LEVEL 3 + struct NodeInfo { uint64_t node_mem; struct HostMemoryBackend *node_memdev; @@ -65,6 +67,30 @@ struct HMAT_LB_Info { }; typedef struct HMAT_LB_Info HMAT_LB_Info; =20 +struct HMAT_Cache_Info { + /* The memory proximity domain to which the memory belongs. */ + uint32_t mem_proximity; + + /* Size of memory side cache in bytes. */ + uint64_t size; + + /* Total cache levels for this memory proximity domain. */ + uint8_t total_levels; + + /* Cache level described in this structure. */ + uint8_t level; + + /* Cache Associativity: None/Direct Mapped/Comple Cache Indexing */ + uint8_t associativity; + + /* Write Policy: None/Write Back(WB)/Write Through(WT) */ + uint8_t write_policy; + + /* Cache Line size in bytes. */ + uint16_t line_size; +}; +typedef struct HMAT_Cache_Info HMAT_Cache_Info; + struct NumaState { /* Number of NUMA nodes */ int num_nodes; @@ -83,6 +109,9 @@ struct NumaState { =20 /* NUMA nodes HMAT Locality Latency and Bandwidth Information */ HMAT_LB_Info *hmat_lb[HMAT_LB_LEVELS][HMAT_LB_TYPES]; + + /* Memory Side Cache Information Structure */ + HMAT_Cache_Info *hmat_cache[MAX_NODES][MAX_HMAT_CACHE_LEVEL + 1]; }; typedef struct NumaState NumaState; =20 @@ -90,6 +119,8 @@ void set_numa_options(MachineState *ms, NumaOptions *obj= ect, Error **errp); void parse_numa_opts(MachineState *ms); void parse_numa_hmat_lb(NumaState *nstat, NumaHmatLBOptions *node, Error **errp); +void parse_numa_hmat_cache(MachineState *ms, NumaHmatCacheOptions *node, + Error **errp); void numa_complete_configuration(MachineState *ms); void query_numa_node_mem(NumaNodeMem node_mem[], MachineState *ms); extern QemuOptsList qemu_numa_opts; diff --git a/qapi/machine.json b/qapi/machine.json index b6019335e8..088be81920 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -428,10 +428,12 @@ # # @hmat-lb: memory latency and bandwidth information (Since: 4.2) # +# @hmat-cache: memory side cache information (Since: 4.2) +# # Since: 2.1 ## { 'enum': 'NumaOptionsType', - 'data': [ 'node', 'dist', 'cpu', 'hmat-lb' ] } + 'data': [ 'node', 'dist', 'cpu', 'hmat-lb', 'hmat-cache' ] } =20 ## # @NumaOptions: @@ -447,7 +449,8 @@ 'node': 'NumaNodeOptions', 'dist': 'NumaDistOptions', 'cpu': 'NumaCpuOptions', - 'hmat-lb': 'NumaHmatLBOptions' }} + 'hmat-lb': 'NumaHmatLBOptions', + 'hmat-cache': 'NumaHmatCacheOptions' }} =20 ## # @NumaNodeOptions: @@ -648,6 +651,80 @@ '*latency': 'time', '*bandwidth': 'size' }} =20 +## +# @HmatCacheAssociativity: +# +# Cache associativity in the Memory Side Cache +# Information Structure of HMAT +# +# For more information of @HmatCacheAssociativity see +# the chapter 5.2.27.5: Table 5-143 of ACPI 6.3 spec. +# +# @none: None +# +# @direct: Direct Mapped +# +# @complex: Complex Cache Indexing (implementation specific) +# +# Since: 4.2 +## +{ 'enum': 'HmatCacheAssociativity', + 'data': [ 'none', 'direct', 'complex' ] } + +## +# @HmatCacheWritePolicy: +# +# Cache write policy in the Memory Side Cache +# Information Structure of HMAT +# +# For more information of @HmatCacheWritePolicy see +# the chapter 5.2.27.5: Table 5-143: Field "Cache Attributes" of ACPI 6.3 = spec. +# +# @none: None +# +# @write-back: Write Back (WB) +# +# @write-through: Write Through (WT) +# +# Since: 4.2 +## +{ 'enum': 'HmatCacheWritePolicy', + 'data': [ 'none', 'write-back', 'write-through' ] } + +## +# @NumaHmatCacheOptions: +# +# Set the memory side cache information for a given memory domain. +# +# For more information of @NumaHmatCacheOptions see +# the chapter 5.2.27.5: Table 5-143: Field "Cache Attributes" of ACPI 6.3 = spec. +# +# @node-id: the memory proximity domain to which the memory belongs. +# +# @size: the size of memory side cache in bytes. +# +# @total: the total cache levels for this memory proximity domain. +# +# @level: the cache level described in this structure. +# +# @assoc: the cache associativity, none/direct-mapped/complex(complex cach= e indexing). +# +# @policy: the write policy, none/write-back/write-through. +# +# @line: the cache Line size in bytes. +# +# Since: 4.2 +## +{ 'struct': 'NumaHmatCacheOptions', + 'data': { + 'node-id': 'uint32', + 'size': 'size', + 'total': 'uint8', + 'level': 'uint8', + 'assoc': 'HmatCacheAssociativity', + 'policy': 'HmatCacheWritePolicy', + 'line': 'uint16' }} + ## # @HostMemPolicy: # diff --git a/qemu-options.hx b/qemu-options.hx index 129da0cdc3..7cf214a653 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -169,7 +169,8 @@ DEF("numa", HAS_ARG, QEMU_OPTION_numa, "-numa node[,memdev=3Did][,cpus=3Dfirstcpu[-lastcpu]][,nodeid=3Dnode][= ,initiator=3Dnode]\n" "-numa dist,src=3Dsource,dst=3Ddestination,val=3Ddistance\n" "-numa cpu,node-id=3Dnode[,socket-id=3Dx][,core-id=3Dy][,thread-id=3Dz= ]\n" - "-numa hmat-lb,initiator=3Dnode,target=3Dnode,hierarchy=3Dmemory|first= -level|second-level|third-level,data-type=3Daccess-latency|read-latency|wri= te-latency[,latency=3Dlat][,bandwidth=3Dbw]\n", + "-numa hmat-lb,initiator=3Dnode,target=3Dnode,hierarchy=3Dmemory|first= -level|second-level|third-level,data-type=3Daccess-latency|read-latency|wri= te-latency[,latency=3Dlat][,bandwidth=3Dbw]\n" + "-numa hmat-cache,node-id=3Dnode,size=3Dsize,total=3Dtotal,level=3Dlev= el[,assoc=3Dnone|direct|complex][,policy=3Dnone|write-back|write-through][,= line=3Dsize]\n", QEMU_ARCH_ALL) STEXI @item -numa node[,mem=3D@var{size}][,cpus=3D@var{firstcpu}[-@var{lastcpu}]= ][,nodeid=3D@var{node}][,initiator=3D@var{initiator}] @@ -177,6 +178,7 @@ STEXI @itemx -numa dist,src=3D@var{source},dst=3D@var{destination},val=3D@var{di= stance} @itemx -numa cpu,node-id=3D@var{node}[,socket-id=3D@var{x}][,core-id=3D@va= r{y}][,thread-id=3D@var{z}] @itemx -numa hmat-lb,initiator=3D@var{node},target=3D@var{node},hierarchy= =3D@var{str},data-type=3D@var{str}[,latency=3D@var{lat}][,bandwidth=3D@var{= bw}] +@itemx -numa hmat-cache,node-id=3D@var{node},size=3D@var{size},total=3D@va= r{total},level=3D@var{level}[,assoc=3D@var{str}][,policy=3D@var{str}][,line= =3D@var{size}] @findex -numa Define a NUMA node and assign RAM and VCPUs to it. Set the NUMA distance from a source node to a destination node. @@ -282,11 +284,19 @@ if NUM is 0, means the corresponding latency or bandw= idth information is not pro And if input numbers without any unit, the latency unit will be 'ps' and t= he bandwidth will be MB/s. =20 +In @samp{hmat-cache} option, @var{node-id} is the NUMA-id of the memory be= longs. +@var{size} is the size of memory side cache in bytes. @var{total} is the t= otal cache levels. +@var{level} is the cache level described in this structure. @var{assoc} is= the cache associativity, +the possible value is 'none/direct(direct-mapped)/complex(complex cache in= dexing)'. +@var{policy} is the write policy. @var{line} is the cache Line size in byt= es. + For example, the following option assigns NUMA node 0 and 1. Node 0 has 2 = cpus and a ram, node 1 has only a ram. The processors in node 0 access memory in no= de 0 with access-latency 5 nanoseconds, access-bandwidth is 200 MB/s; The processors in NUMA node 0 access memory in NUMA node 1 with access-lat= ency 10 nanoseconds, access-bandwidth is 100 MB/s. +And for memory side cache information, NUMA node 0 and 1 both have 1 level= memory +cache, size is 0x20000 bytes, policy is write-back, the cache Line size is= 8 bytes: @example -machine hmat=3Don \ -m 2G \ @@ -300,7 +310,9 @@ nanoseconds, access-bandwidth is 100 MB/s. -numa hmat-lb,initiator=3D0,target=3D0,hierarchy=3Dmemory,data-type=3Dacce= ss-latency,latency=3D5ns \ -numa hmat-lb,initiator=3D0,target=3D0,hierarchy=3Dmemory,data-type=3Dacce= ss-bandwidth,bandwidth=3D200M \ -numa hmat-lb,initiator=3D0,target=3D1,hierarchy=3Dmemory,data-type=3Dacce= ss-latency,latency=3D10ns \ --numa hmat-lb,initiator=3D0,target=3D1,hierarchy=3Dmemory,data-type=3Dacce= ss-bandwidth,bandwidth=3D100M +-numa hmat-lb,initiator=3D0,target=3D1,hierarchy=3Dmemory,data-type=3Dacce= ss-bandwidth,bandwidth=3D100M \ +-numa hmat-cache,node-id=3D0,size=3D0x20000,total=3D1,level=3D1,assoc=3Ddi= rect,policy=3Dwrite-back,line=3D8 \ +-numa hmat-cache,node-id=3D1,size=3D0x20000,total=3D1,level=3D1,assoc=3Ddi= rect,policy=3Dwrite-back,line=3D8 @end example =20 ETEXI --=20 2.20.1 From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568266786; cv=none; d=zoho.com; s=zohoarc; b=KQuEwfzz0nJOj3SjFfDY8gpeU84gFgXjuCDorEzc5uaRGXE4OySO34HvSjwhgUMFzVlMlJvAp3X3DAs7luoER4kR0wg30gYmRUyWLE9RtrfyQF+Wu9RaIE7Wq2Ij7vPLJIz0wGLKR6mWyFW+TW5ezpYuU73QZ9GOg4by6GYKWuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568266786; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=IWerszHajNHWtsCGI4pzXk95/a/wo8h0oiqRcdasm+8=; b=DSvsxijj0mjl1o07q+XTxzTjO7CbipumlljWvwVLH3zX9cjpxA+GNmnB0nOyfyLwa/+Cl/AadBQtSqoVByJj9HVi5xb4uV5FrsjrG/E9Tm6uboouVtKjCNK8/8x1V4kEEX1jkvCEPQ7QI/nio7TLzZS98sGWm8OiW7NfDwm4lr4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568266786653551.4286424435587; Wed, 11 Sep 2019 22:39:46 -0700 (PDT) Received: from localhost ([::1]:58234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8HpO-0005Q7-Rc for importer@patchew.org; Thu, 12 Sep 2019 01:39:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56598) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hmx-0003Y4-Jo for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hmv-0002zH-Cd for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:03 -0400 Received: from mga11.intel.com ([192.55.52.93]:18620) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hmv-0002ye-22 for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:01 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:37:00 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:36:57 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030797" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:35 +0800 Message-Id: <20190912053638.4858-9-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 08/11] hmat acpi: Build Memory Proximity Domain Attributes Structure(s) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, Daniel Black , Jonathan Cameron , dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Liu Jingqi HMAT is defined in ACPI 6.3: 5.2.27 Heterogeneous Memory Attribute Table (HMAT). The specification references below link: http://www.uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf It describes the memory attributes, such as memory side cache attributes and bandwidth and latency details, related to the Memory Proximity Domain. The software is expected to use this information as hint for optimization. This structure describes Memory Proximity Domain Attributes by memory subsystem and its associativity with processor proximity domain as well as hint for memory usage. In the linux kernel, the codes in drivers/acpi/hmat/hmat.c parse and report the platform's HMAT tables. Reviewed-by: Daniel Black Reviewed-by: Jonathan Cameron Signed-off-by: Liu Jingqi Signed-off-by: Tao Xu --- Changes in v11: - Move numa option patches forward. --- hw/acpi/Kconfig | 5 +++ hw/acpi/Makefile.objs | 1 + hw/acpi/hmat.c | 101 ++++++++++++++++++++++++++++++++++++++++++ hw/acpi/hmat.h | 45 +++++++++++++++++++ hw/i386/acpi-build.c | 5 +++ 5 files changed, 157 insertions(+) create mode 100644 hw/acpi/hmat.c create mode 100644 hw/acpi/hmat.h diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig index 7c59cf900b..039bb99efa 100644 --- a/hw/acpi/Kconfig +++ b/hw/acpi/Kconfig @@ -7,6 +7,7 @@ config ACPI_X86 select ACPI_NVDIMM select ACPI_CPU_HOTPLUG select ACPI_MEMORY_HOTPLUG + select ACPI_HMAT =20 config ACPI_X86_ICH bool @@ -31,3 +32,7 @@ config ACPI_VMGENID bool default y depends on PC + +config ACPI_HMAT + bool + depends on ACPI diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 9bb2101e3b..c05019b059 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -6,6 +6,7 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) +=3D memory_hotplu= g.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) +=3D cpu.o common-obj-$(CONFIG_ACPI_NVDIMM) +=3D nvdimm.o common-obj-$(CONFIG_ACPI_VMGENID) +=3D vmgenid.o +common-obj-$(CONFIG_ACPI_HMAT) +=3D hmat.o common-obj-$(call lnot,$(CONFIG_ACPI_X86)) +=3D acpi-stub.o =20 common-obj-y +=3D acpi_interface.o diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c new file mode 100644 index 0000000000..1368fce7ee --- /dev/null +++ b/hw/acpi/hmat.c @@ -0,0 +1,101 @@ +/* + * HMAT ACPI Implementation + * + * Copyright(C) 2019 Intel Corporation. + * + * Author: + * Liu jingqi + * Tao Xu + * + * HMAT is defined in ACPI 6.3: 5.2.27 Heterogeneous Memory Attribute Table + * (HMAT) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "sysemu/numa.h" +#include "hw/acpi/hmat.h" + +/* + * ACPI 6.3: + * 5.2.27.3 Memory Proximity Domain Attributes Structure: Table 5-145 + */ +static void build_hmat_mpda(GArray *table_data, uint16_t flags, int initia= tor, + int mem_node) +{ + + /* Memory Proximity Domain Attributes Structure */ + /* Type */ + build_append_int_noprefix(table_data, 0, 2); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 2); + /* Length */ + build_append_int_noprefix(table_data, 40, 4); + /* Flags */ + build_append_int_noprefix(table_data, flags, 2); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 2); + /* Proximity Domain for the Attached Initiator */ + build_append_int_noprefix(table_data, initiator, 4); + /* Proximity Domain for the Memory */ + build_append_int_noprefix(table_data, mem_node, 4); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 4); + /* + * Reserved: + * Previously defined as the Start Address of the System Physical + * Address Range. Deprecated since ACPI Spec 6.3. + */ + build_append_int_noprefix(table_data, 0, 8); + /* + * Reserved: + * Previously defined as the Range Length of the region in bytes. + * Deprecated since ACPI Spec 6.3. + */ + build_append_int_noprefix(table_data, 0, 8); +} + +/* Build HMAT sub table structures */ +static void hmat_build_table_structs(GArray *table_data, NumaState *nstat) +{ + uint16_t flags; + int i; + + for (i =3D 0; i < nstat->num_nodes; i++) { + flags =3D 0; + + if (nstat->nodes[i].initiator_valid) { + flags |=3D HMAT_PROX_INIT_VALID; + } + + build_hmat_mpda(table_data, flags, nstat->nodes[i].initiator, i); + } +} + +void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *nstat) +{ + uint64_t hmat_start; + + hmat_start =3D table_data->len; + + /* reserve space for HMAT header */ + acpi_data_push(table_data, 40); + + hmat_build_table_structs(table_data, nstat); + + build_header(linker, table_data, + (void *)(table_data->data + hmat_start), + "HMAT", table_data->len - hmat_start, 2, NULL, NULL); +} diff --git a/hw/acpi/hmat.h b/hw/acpi/hmat.h new file mode 100644 index 0000000000..0c1839cf6f --- /dev/null +++ b/hw/acpi/hmat.h @@ -0,0 +1,45 @@ +/* + * HMAT ACPI Implementation Header + * + * Copyright(C) 2019 Intel Corporation. + * + * Author: + * Liu jingqi + * Tao Xu + * + * HMAT is defined in ACPI 6.3: 5.2.27 Heterogeneous Memory Attribute Table + * (HMAT) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#ifndef HMAT_H +#define HMAT_H + +#include "hw/acpi/acpi-defs.h" +#include "hw/acpi/acpi.h" +#include "hw/acpi/bios-linker-loader.h" +#include "hw/acpi/aml-build.h" + +/* + * ACPI 6.3: 5.2.27.3 Memory Proximity Domain Attributes Structure, + * Table 5-145, Field "flag", Bit [0]: set to 1 to indicate that data in + * the Proximity Domain for the Attached Initiator field is valid. + * Other bits reserved. + */ +#define HMAT_PROX_INIT_VALID 0x1 + +void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *nstat); + +#endif diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index e54e571a75..7f2e05f1a9 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -68,6 +68,7 @@ #include "hw/i386/intel_iommu.h" =20 #include "hw/acpi/ipmi.h" +#include "hw/acpi/hmat.h" =20 /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and * -M pc-i440fx-2.0. Even if the actual amount of AML generated grows @@ -2698,6 +2699,10 @@ void acpi_build(AcpiBuildTables *tables, MachineStat= e *machine) acpi_add_table(table_offsets, tables_blob); build_slit(tables_blob, tables->linker, machine); } + if (machine->numa_state->hmat_enabled) { + acpi_add_table(table_offsets, tables_blob); + build_hmat(tables_blob, tables->linker, machine->numa_state); + } } if (acpi_get_mcfg(&mcfg)) { acpi_add_table(table_offsets, tables_blob); --=20 2.20.1 From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568266943; cv=none; d=zoho.com; s=zohoarc; b=AFdanQaAVJu7rCQwTFe3bgacXvf8JiKXT5vYBH4sb/YIaXkLAY7Cyrl+ln6l/nIBVk/HGro6N8d37Ovp3hFr9CwD0wSGsjB5dGQmgjjCV6xAe0wYzKSeFXxfhlE1Tgg+3fw8IpWANIxSMVYKLFlunWGbT8weUBU0pLWsVpQX0xk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568266943; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=J6kmF6vlLNs7H65KZdEh9zhF1ZTQvZKDM8mlGQEecHg=; b=hqdG9t8ZEZuUU7KJ5fNCBREyPsYi0YE1VbyoxRH5OMHDKA583zqEGNL8wskQTqGYQ2Q74TKEZUz1+V39LeDluCdO6U0sZgQWU66tvOX9FqnpYYmdoZGX4dkh3lXCNmoPqs5FJBkQz/Z5RaztarTpQtYQlIAzQXMuH50aPv0MSMY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156826694342522.14230252912955; Wed, 11 Sep 2019 22:42:23 -0700 (PDT) Received: from localhost ([::1]:58252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hs5-0000Oa-Ra for importer@patchew.org; Thu, 12 Sep 2019 01:42:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56605) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hmy-0003Zs-U3 for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hmx-00030I-9P for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:04 -0400 Received: from mga11.intel.com ([192.55.52.93]:18624) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hmx-0002zn-07 for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:03 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:37:02 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:37:00 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030806" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:36 +0800 Message-Id: <20190912053638.4858-10-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 09/11] hmat acpi: Build System Locality Latency and Bandwidth Information Structure(s) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, jonathan.cameron@huawei.com, dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Liu Jingqi This structure describes the memory access latency and bandwidth information from various memory access initiator proximity domains. The latency and bandwidth numbers represented in this structure correspond to rated latency and bandwidth for the platform. The software could use this information as hint for optimization. Signed-off-by: Liu Jingqi Signed-off-by: Tao Xu --- Changes in v11: - Calculate base in build_hmat_lb(). --- hw/acpi/hmat.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++- hw/acpi/hmat.h | 2 + 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c index 1368fce7ee..2d76dd0cd1 100644 --- a/hw/acpi/hmat.c +++ b/hw/acpi/hmat.c @@ -27,6 +27,7 @@ #include "qemu/osdep.h" #include "sysemu/numa.h" #include "hw/acpi/hmat.h" +#include "qemu/error-report.h" =20 /* * ACPI 6.3: @@ -67,11 +68,105 @@ static void build_hmat_mpda(GArray *table_data, uint16= _t flags, int initiator, build_append_int_noprefix(table_data, 0, 8); } =20 +static bool entry_overflow(uint64_t *lb_data, uint64_t base, int len) +{ + int i; + + for (i =3D 0; i < len; i++) { + if (lb_data[i] / base >=3D UINT16_MAX) { + return true; + } + } + + return false; +} +/* + * ACPI 6.3: 5.2.27.4 System Locality Latency and Bandwidth Information + * Structure: Table 5-146 + */ +static void build_hmat_lb(GArray *table_data, HMAT_LB_Info *hmat_lb, + uint32_t num_initiator, uint32_t num_target, + uint32_t *initiator_list, int type) +{ + uint8_t mask =3D 0x0f; + uint32_t s =3D num_initiator; + uint32_t t =3D num_target; + uint64_t base =3D 1; + uint64_t *lb_data; + int i, unit; + + /* Type */ + build_append_int_noprefix(table_data, 1, 2); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 2); + /* Length */ + build_append_int_noprefix(table_data, 32 + 4 * s + 4 * t + 2 * s * t, = 4); + /* Flags: Bits [3:0] Memory Hierarchy, Bits[7:4] Reserved */ + build_append_int_noprefix(table_data, hmat_lb->hierarchy & mask, 1); + /* Data Type */ + build_append_int_noprefix(table_data, hmat_lb->data_type, 1); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 2); + /* Number of Initiator Proximity Domains (s) */ + build_append_int_noprefix(table_data, s, 4); + /* Number of Target Proximity Domains (t) */ + build_append_int_noprefix(table_data, t, 4); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 4); + + if (HMAT_IS_LATENCY(type)) { + unit =3D 1000; + lb_data =3D hmat_lb->latency; + } else { + unit =3D 1024; + lb_data =3D hmat_lb->bandwidth; + } + + while (entry_overflow(lb_data, base, s * t)) { + for (i =3D 0; i < s * t; i++) { + if (!QEMU_IS_ALIGNED(lb_data[i], unit * base)) { + error_report("Invalid latency/bandwidth input, all " + "latencies/bandwidths should be specified in the same unit= s."); + exit(1); + } + } + base *=3D unit; + } + + /* Entry Base Unit */ + build_append_int_noprefix(table_data, base, 8); + + /* Initiator Proximity Domain List */ + for (i =3D 0; i < s; i++) { + build_append_int_noprefix(table_data, initiator_list[i], 4); + } + + /* Target Proximity Domain List */ + for (i =3D 0; i < t; i++) { + build_append_int_noprefix(table_data, i, 4); + } + + /* Latency or Bandwidth Entries */ + for (i =3D 0; i < s * t; i++) { + uint16_t entry; + + if (HMAT_IS_LATENCY(type)) { + entry =3D hmat_lb->latency[i] / base; + } else { + entry =3D hmat_lb->bandwidth[i] / base; + } + + build_append_int_noprefix(table_data, entry, 2); + } +} + /* Build HMAT sub table structures */ static void hmat_build_table_structs(GArray *table_data, NumaState *nstat) { uint16_t flags; - int i; + uint32_t *initiator_list; + int i, j, hrchy, type; + HMAT_LB_Info *numa_hmat_lb; =20 for (i =3D 0; i < nstat->num_nodes; i++) { flags =3D 0; @@ -82,6 +177,32 @@ static void hmat_build_table_structs(GArray *table_data= , NumaState *nstat) =20 build_hmat_mpda(table_data, flags, nstat->nodes[i].initiator, i); } + + initiator_list =3D g_malloc0(nstat->num_initiator * sizeof(uint32_t)); + for (i =3D 0, j =3D 0; i < nstat->num_nodes; i++) { + if (nstat->nodes[i].has_cpu) { + initiator_list[j] =3D i; + j++; + } + } + + /* + * ACPI 6.3: 5.2.27.4 System Locality Latency and Bandwidth Information + * Structure: Table 5-146 + */ + for (hrchy =3D HMAT_LB_MEM_MEMORY; + hrchy <=3D HMAT_LB_MEM_CACHE_3RD_LEVEL; hrchy++) { + for (type =3D HMAT_LB_DATA_ACCESS_LATENCY; + type <=3D HMAT_LB_DATA_WRITE_BANDWIDTH; type++) { + numa_hmat_lb =3D nstat->hmat_lb[hrchy][type]; + + if (numa_hmat_lb) { + build_hmat_lb(table_data, numa_hmat_lb, nstat->num_initiat= or, + nstat->num_nodes, initiator_list, type); + } + } + } + g_free(initiator_list); } =20 void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *nstat) diff --git a/hw/acpi/hmat.h b/hw/acpi/hmat.h index 0c1839cf6f..1154dfb48e 100644 --- a/hw/acpi/hmat.h +++ b/hw/acpi/hmat.h @@ -40,6 +40,8 @@ */ #define HMAT_PROX_INIT_VALID 0x1 =20 +#define HMAT_IS_LATENCY(type) (type <=3D HMAT_LB_DATA_WRITE_LATENCY) + void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *nstat); =20 #endif --=20 2.20.1 From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568267457; cv=none; d=zoho.com; s=zohoarc; b=eDaKRfYBrM6FNvMNIgBmqgE241a7v+lrSjR/Lx0Hi3RTN0WWaHlD+6uT3KtxhL0haNyLWbJNNPKZH9mx+u8lXj55vw+KvICH80VLCYWf40yM6nMTKeJ8CAts4hwgTFJpfBrPn1Yl+or01zZ3nd4L/1EEI2FHuI6xJ2j1cKHGV/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568267457; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=5smpkC/T87ZECnMWGlrZ4qkRacle+zEnFnvzruyKd5c=; b=g3QuUV39cIegc0OMDBSvxp7jArtOZv751ZB7W2fppUY9kiqQTqv69F21wT6TzwtRKRYKC205Ez+rvEll+Eki+06jGZVFPNbln5WRfTDhjnnCgFjKqbqjMZblE7vPNwEue0ihHWQadE7GYgvZsxaD6icczComQajNrqrizRFnIN4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568267457236122.67037990111112; Wed, 11 Sep 2019 22:50:57 -0700 (PDT) Received: from localhost ([::1]:58314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8I0I-0007Y3-KL for importer@patchew.org; Thu, 12 Sep 2019 01:50:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56624) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hn1-0003bx-1m for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hmy-000315-Kb for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:06 -0400 Received: from mga11.intel.com ([192.55.52.93]:18624) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hmy-0002zn-8C for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:04 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:37:03 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:37:02 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030821" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:37 +0800 Message-Id: <20190912053638.4858-11-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 10/11] hmat acpi: Build Memory Side Cache Information Structure(s) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, Daniel Black , Jonathan Cameron , dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Liu Jingqi This structure describes memory side cache information for memory proximity domains if the memory side cache is present and the physical device forms the memory side cache. The software could use this information to effectively place the data in memory to maximize the performance of the system memory that use the memory side cache. Reviewed-by: Daniel Black Reviewed-by: Jonathan Cameron Signed-off-by: Liu Jingqi Signed-off-by: Tao Xu --- Changes in v11: - Move numa option patches forward. --- hw/acpi/hmat.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c index 2d76dd0cd1..17a6afec99 100644 --- a/hw/acpi/hmat.c +++ b/hw/acpi/hmat.c @@ -160,13 +160,62 @@ static void build_hmat_lb(GArray *table_data, HMAT_LB= _Info *hmat_lb, } } =20 +/* ACPI 6.3: 5.2.27.5 Memory Side Cache Information Structure: Table 5-147= */ +static void build_hmat_cache(GArray *table_data, HMAT_Cache_Info *hmat_cac= he) +{ + /* + * Cache Attributes: Bits [3:0] =E2=80=93 Total Cache Levels + * for this Memory Proximity Domain + */ + uint32_t cache_attr =3D hmat_cache->total_levels & 0xF; + + /* Bits [7:4] : Cache Level described in this structure */ + cache_attr |=3D (hmat_cache->level & 0xF) << 4; + + /* Bits [11:8] - Cache Associativity */ + cache_attr |=3D (hmat_cache->associativity & 0xF) << 8; + + /* Bits [15:12] - Write Policy */ + cache_attr |=3D (hmat_cache->write_policy & 0xF) << 12; + + /* Bits [31:16] - Cache Line size in bytes */ + cache_attr |=3D (hmat_cache->line_size & 0xFFFF) << 16; + + cache_attr =3D cpu_to_le32(cache_attr); + + /* Type */ + build_append_int_noprefix(table_data, 2, 2); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 2); + /* Length */ + build_append_int_noprefix(table_data, 32, 4); + /* Proximity Domain for the Memory */ + build_append_int_noprefix(table_data, hmat_cache->mem_proximity, 4); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 4); + /* Memory Side Cache Size */ + build_append_int_noprefix(table_data, hmat_cache->size, 8); + /* Cache Attributes */ + build_append_int_noprefix(table_data, cache_attr, 4); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 2); + /* + * Number of SMBIOS handles (n) + * Linux kernel uses Memory Side Cache Information Structure + * without SMBIOS entries for now, so set Number of SMBIOS handles + * as 0. + */ + build_append_int_noprefix(table_data, 0, 2); +} + /* Build HMAT sub table structures */ static void hmat_build_table_structs(GArray *table_data, NumaState *nstat) { uint16_t flags; uint32_t *initiator_list; - int i, j, hrchy, type; + int i, j, hrchy, type, level; HMAT_LB_Info *numa_hmat_lb; + HMAT_Cache_Info *numa_hmat_cache; =20 for (i =3D 0; i < nstat->num_nodes; i++) { flags =3D 0; @@ -202,6 +251,19 @@ static void hmat_build_table_structs(GArray *table_dat= a, NumaState *nstat) } } } + + /* + * ACPI 6.3: 5.2.27.5 Memory Side Cache Information Structure: + * Table 5-147 + */ + for (i =3D 0; i < nstat->num_nodes; i++) { + for (level =3D 0; level <=3D MAX_HMAT_CACHE_LEVEL; level++) { + numa_hmat_cache =3D nstat->hmat_cache[i][level]; + if (numa_hmat_cache) { + build_hmat_cache(table_data, numa_hmat_cache); + } + } + } g_free(initiator_list); } =20 --=20 2.20.1 From nobody Fri May 3 07:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568267146; cv=none; d=zoho.com; s=zohoarc; b=D4pZgdmEYXWT821NAKz3jADPk+pFyDj1BAbI6akmmvkqZjzznFMyNDRseni7wCbBrhCOmCUPAENswG4Oorkrak+ROsDFVW4VmtK8sdUPxjq6Nb/Pse9/K7ky7d2kZRL5iW4Psw2deqqq0rakkYKmS2aUnTzlW+Ur9ZzeBPyA2kg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568267146; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=o1xVXsmFjW9mMM/hxVSlFP8Aq33mN+M91Zo85GMUNHg=; b=oDqZ8Jcjro5nF0SoEnDpGZvXTtfaO5oV7fxNkOH7W/CtY0vzICAOsJ4W8RQGrLCVS6pWljFWCRNayObarGSEoMK6Xm3R27EM77Vacbr7a2Vp/G97MaGEHrj4q1EbvWQqSqNxpg0oX0E24PKLM5LF1RJeVOlvcvscdmVBZ1W1K78= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568267146593219.8400580306536; Wed, 11 Sep 2019 22:45:46 -0700 (PDT) Received: from localhost ([::1]:58274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8HvI-00032V-15 for importer@patchew.org; Thu, 12 Sep 2019 01:45:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56631) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8Hn1-0003d3-Lc for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8Hn0-00031e-Fg for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:07 -0400 Received: from mga11.intel.com ([192.55.52.93]:18624) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8Hn0-0002zn-7n for qemu-devel@nongnu.org; Thu, 12 Sep 2019 01:37:06 -0400 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2019 22:37:05 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2019 22:37:04 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,495,1559545200"; d="scan'208";a="186030828" From: Tao Xu To: imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com Date: Thu, 12 Sep 2019 13:36:38 +0800 Message-Id: <20190912053638.4858-12-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190912053638.4858-1-tao3.xu@intel.com> References: <20190912053638.4858-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v11 11/11] tests/bios-tables-test: add test cases for ACPI HMAT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jingqi Liu , tao3.xu@intel.com, fan.du@intel.com, qemu-devel@nongnu.org, Daniel Black , jonathan.cameron@huawei.com, dan.j.williams@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" ACPI table HMAT has been introduced, QEMU now builds HMAT tables for Heterogeneous Memory with boot option '-numa node'. Add test cases on PC and Q35 machines with 2 numa nodes. Because HMAT is generated when system enable numa, the following tables need to be added for this test: tests/acpi-test-data/pc/*.acpihmat tests/acpi-test-data/pc/HMAT.* tests/acpi-test-data/q35/*.acpihmat tests/acpi-test-data/q35/HMAT.* Reviewed-by: Daniel Black Reviewed-by: Jingqi Liu Suggested-by: Igor Mammedov Signed-off-by: Tao Xu --- No changes in V11. Changes in v10: - Update test case, add "-machine hmat=3Don" --- tests/bios-tables-test.c | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 9b3d8b0d1b..976788b6fa 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -870,6 +870,48 @@ static void test_acpi_piix4_tcg_dimm_pxm(void) test_acpi_tcg_dimm_pxm(MACHINE_PC); } =20 +static void test_acpi_tcg_acpi_hmat(const char *machine) +{ + test_data data; + + memset(&data, 0, sizeof(data)); + data.machine =3D machine; + data.variant =3D ".acpihmat"; + test_acpi_one(" -machine hmat=3Don" + " -smp 2,sockets=3D2" + " -m 128M,slots=3D2,maxmem=3D1G" + " -object memory-backend-ram,size=3D64M,id=3Dm0" + " -object memory-backend-ram,size=3D64M,id=3Dm1" + " -numa node,nodeid=3D0,memdev=3Dm0" + " -numa node,nodeid=3D1,memdev=3Dm1,initiator=3D0" + " -numa cpu,node-id=3D0,socket-id=3D0" + " -numa cpu,node-id=3D0,socket-id=3D1" + " -numa hmat-lb,initiator=3D0,target=3D0,hierarchy=3Dmem= ory," + "data-type=3Daccess-latency,latency=3D5ns" + " -numa hmat-lb,initiator=3D0,target=3D0,hierarchy=3Dmem= ory," + "data-type=3Daccess-bandwidth,bandwidth=3D500M" + " -numa hmat-lb,initiator=3D0,target=3D1,hierarchy=3Dmem= ory," + "data-type=3Daccess-latency,latency=3D10ns" + " -numa hmat-lb,initiator=3D0,target=3D1,hierarchy=3Dmem= ory," + "data-type=3Daccess-bandwidth,bandwidth=3D100M" + " -numa hmat-cache,node-id=3D0,size=3D0x20000,total=3D1,= level=3D1" + ",assoc=3Ddirect,policy=3Dwrite-back,line=3D8" + " -numa hmat-cache,node-id=3D1,size=3D0x20000,total=3D1,= level=3D1" + ",assoc=3Ddirect,policy=3Dwrite-back,line=3D8", + &data); + free_test_data(&data); +} + +static void test_acpi_q35_tcg_acpi_hmat(void) +{ + test_acpi_tcg_acpi_hmat(MACHINE_Q35); +} + +static void test_acpi_piix4_tcg_acpi_hmat(void) +{ + test_acpi_tcg_acpi_hmat(MACHINE_PC); +} + static void test_acpi_virt_tcg(void) { test_data data =3D { @@ -914,6 +956,8 @@ int main(int argc, char *argv[]) qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem); qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm); qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm); + qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hma= t); + qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat); } else if (strcmp(arch, "aarch64") =3D=3D 0) { qtest_add_func("acpi/virt", test_acpi_virt_tcg); } --=20 2.20.1