From nobody Wed May 1 00:40:29 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=1574409390; cv=none; d=zoho.com; s=zohoarc; b=dz4+QR6jNgAroYlCu0ik0QcSOITxD9ZhlOEimOwcb2hX0+iN9jSbU5CgziRIBuBDg9Gl/3BG5xMJDz+l0wFWShbp7deUP4mqXedU9OJEowtaeYSHc7rmvZTQ5++OM3JpPtFOSQ2AtLkUy/JB0lSN5usPwzWdvYoQF9NM7APCVvg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409390; 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; bh=u8H5oO4WsGLVIYi3ts7/Fy94jpIGNtFRMxYey4l1pXw=; b=JPw5btBEjzf3vEv1gvV9yi1GsqrIV+7SZgWLrWI5cr1znqMlBzAWz6yF9vapzwgF88QznK9E5dQGKI5hda7Fd710XWkBb8iIx5KaEcR5tSSSkcOb9mSMxu92qBIcqshBWR/d37MtQbMIZRBa3msLK7ZElxRiASa1EoBzCPBIFmA= 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 1574409390313134.6373201352344; Thu, 21 Nov 2019 23:56:30 -0800 (PST) Received: from localhost ([::1]:48002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3nm-0005HD-SZ for importer@patchew.org; Fri, 22 Nov 2019 02:56:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39459) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gI-0005Ev-Ts for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gH-0002lo-0Q for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:42 -0500 Received: from mga18.intel.com ([134.134.136.126]:36766) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gG-0002j8-Nu for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:40 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:48:35 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:48:32 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178449" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 01/14] util/cutils: Add Add qemu_strtold and qemu_strtold_finite Date: Fri, 22 Nov 2019 15:48:13 +0800 Message-Id: <20191122074826.1373-2-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Work like qemu_strtod() and qemu_strtold_finite, except store long double. Signed-off-by: Tao Xu Reviewed-by: Markus Armbruster --- No changes in v17. --- include/qemu/cutils.h | 3 +++ util/cutils.c | 48 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index b54c847e0f..48cf9bf776 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -146,6 +146,9 @@ int qemu_strtou64(const char *nptr, const char **endptr= , int base, uint64_t *result); int qemu_strtod(const char *nptr, const char **endptr, double *result); int qemu_strtod_finite(const char *nptr, const char **endptr, double *resu= lt); +int qemu_strtold(const char *nptr, const char **endptr, long double *resul= t); +int qemu_strtold_finite(const char *nptr, const char **endptr, + long double *result); =20 int parse_uint(const char *s, unsigned long long *value, char **endptr, int base); diff --git a/util/cutils.c b/util/cutils.c index fd591cadf0..5db3b2add5 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -553,7 +553,7 @@ int qemu_strtou64(const char *nptr, const char **endptr= , int base, =20 /** * Convert string @nptr to a double. - * + * * This is a wrapper around strtod() that is harder to misuse. * Semantics of @nptr and @endptr match strtod() with differences * noted below. @@ -616,6 +616,52 @@ int qemu_strtod_finite(const char *nptr, const char **= endptr, double *result) return ret; } =20 +/* + * Convert string @nptr to a long double. + * + * Works like qemu_strtod(), except it stores long double. + */ +int qemu_strtold(const char *nptr, const char **endptr, long double *resul= t) +{ + char *ep; + + if (!nptr) { + if (endptr) { + *endptr =3D nptr; + } + return -EINVAL; + } + + errno =3D 0; + *result =3D strtold(nptr, &ep); + return check_strtox_error(nptr, ep, endptr, errno); +} + +/* + * Convert string @nptr to a finite long double. + * + * Works like qemu_strtod_finite(), except it stores long double. + */ +int qemu_strtold_finite(const char *nptr, const char **endptr, + long double *result) +{ + long double tmp; + int ret; + + ret =3D qemu_strtold(nptr, endptr, &tmp); + if (!ret && !isfinite(tmp)) { + if (endptr) { + *endptr =3D nptr; + } + ret =3D -EINVAL; + } + + if (ret !=3D -EINVAL) { + *result =3D tmp; + } + return ret; +} + /** * Searches for the first occurrence of 'c' in 's', and returns a pointer * to the trailing null byte if none was found. --=20 2.20.1 From nobody Wed May 1 00:40:29 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=1574409028; cv=none; d=zoho.com; s=zohoarc; b=NZtbV9SfsWpz+IxVpmcCcZW5qhD8n5rC3KhqJV1hAYD2X6tuRWZN4N4J+RhP0pHabC9J4s2QsZDUz8cIyqgmsTkmmV7H7C4egOf5Wv+f+jxoo7Cx3N0WAYNWze+GQR0p7Yqny/g8exc/nJo7DXIrC+7dTi4D0rf0UOTLwYTERM0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409028; 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; bh=hjuRD1FBU4B8mbycuUVhbrX4Y1WM3W2S72LaREydNNs=; b=avRrwa55rOPLI3P7JTR6vy4kAS1DtIzmE75A4BkdW9AuFJJW7UZyqcMlzH1GQIEGKLp/jZoq9FWjLnnZhsbdKPB+n1zmsgXoGppAkXaCF3onxP8/senDAJBTwvSzZPIgC2QFlJG4j/vdt+BBWEhXMIa/+I/qeZndgUZqB5hPTSE= 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 1574409028700760.6491031359914; Thu, 21 Nov 2019 23:50:28 -0800 (PST) Received: from localhost ([::1]:47944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3hz-0006jW-Ey for importer@patchew.org; Fri, 22 Nov 2019 02:50:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39474) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gJ-0005GW-A5 for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gH-0002m9-Ot for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:43 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gH-0002kF-Gj for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:41 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:48:38 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:48:35 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178459" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 02/14] util/cutils: Use qemu_strtold_finite to parse size Date: Fri, 22 Nov 2019 15:48:14 +0800 Message-Id: <20191122074826.1373-3-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Support full 64bit precision, modify related test cases. Signed-off-by: Tao Xu --- No changes in v17. --- tests/test-cutils.c | 41 +++++------------------------------- tests/test-keyval.c | 47 +++++++----------------------------------- tests/test-qemu-opts.c | 39 +++++++---------------------------- util/cutils.c | 13 +++++------- 4 files changed, 24 insertions(+), 116 deletions(-) diff --git a/tests/test-cutils.c b/tests/test-cutils.c index 1aa8351520..465514b85f 100644 --- a/tests/test-cutils.c +++ b/tests/test-cutils.c @@ -1970,40 +1970,19 @@ static void test_qemu_strtosz_simple(void) g_assert_cmpint(err, =3D=3D, 0); g_assert_cmpint(res, =3D=3D, 12345); =20 - /* Note: precision is 53 bits since we're parsing with strtod() */ + /* Note: precision is 64 bits (UINT64_MAX) */ =20 - str =3D "9007199254740991"; /* 2^53-1 */ + str =3D "18446744073709551614"; /* UINT64_MAX - 1 */ err =3D qemu_strtosz(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_strtosz(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_strtosz(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_strtosz(str, &endptr, &res); - g_assert_cmpint(err, =3D=3D, 0); - g_assert_cmpint(res, =3D=3D, 0xfffffffffffff800); + g_assert_cmpint(res, =3D=3D, 0xfffffffffffffffe); g_assert(endptr =3D=3D str + 20); =20 - str =3D "18446744073709550591"; /* 0xfffffffffffffbff */ + str =3D "18446744073709551615"; /* UINT64_MAX */ err =3D qemu_strtosz(str, &endptr, &res); g_assert_cmpint(err, =3D=3D, 0); - g_assert_cmpint(res, =3D=3D, 0xfffffffffffff800); /* rounded to 53 bit= s */ + g_assert_cmpint(res, =3D=3D, 0xffffffffffffffff); g_assert(endptr =3D=3D str + 20); - - /* 0x7ffffffffffffe00..0x7fffffffffffffff get rounded to - * 0x8000000000000000, thus -ERANGE; see test_qemu_strtosz_erange() */ } =20 static void test_qemu_strtosz_units(void) @@ -2145,16 +2124,6 @@ static void test_qemu_strtosz_erange(void) g_assert_cmpint(err, =3D=3D, -ERANGE); g_assert(endptr =3D=3D str + 2); =20 - str =3D "18446744073709550592"; /* 0xfffffffffffffc00 */ - err =3D qemu_strtosz(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_strtosz(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_strtosz(str, &endptr, &res); g_assert_cmpint(err, =3D=3D, -ERANGE); diff --git a/tests/test-keyval.c b/tests/test-keyval.c index 09b0ae3c68..fad941fcb8 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -383,59 +383,26 @@ static void test_keyval_visit_size(void) visit_end_struct(v, NULL); visit_free(v); =20 - /* Note: precision is 53 bits since we're parsing with strtod() */ + /* Note: precision is 64 bits (UINT64_MAX) */ =20 - /* Around limit of precision: 2^53-1, 2^53, 2^53+1 */ - qdict =3D keyval_parse("sz1=3D9007199254740991," - "sz2=3D9007199254740992," - "sz3=3D9007199254740993", + /* Around limit of precision: UINT64_MAX - 1, UINT64_MAX */ + qdict =3D keyval_parse("sz1=3D18446744073709551614," + "sz2=3D18446744073709551615", 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_size(v, "sz1", &sz, &error_abort); - g_assert_cmphex(sz, =3D=3D, 0x1fffffffffffff); + g_assert_cmphex(sz, =3D=3D, 0xfffffffffffffffe); visit_type_size(v, "sz2", &sz, &error_abort); - g_assert_cmphex(sz, =3D=3D, 0x20000000000000); - visit_type_size(v, "sz3", &sz, &error_abort); - g_assert_cmphex(sz, =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("sz1=3D9223372036854774784," /* 7ffffffffffffc0= 0 */ - "sz2=3D9223372036854775295", /* 7ffffffffffffdff = */ - 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_size(v, "sz1", &sz, &error_abort); - g_assert_cmphex(sz, =3D=3D, 0x7ffffffffffffc00); - visit_type_size(v, "sz2", &sz, &error_abort); - g_assert_cmphex(sz, =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("sz1=3D18446744073709549568," /* fffffffffffff8= 00 */ - "sz2=3D18446744073709550591", /* fffffffffffffbff= */ - 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_size(v, "sz1", &sz, &error_abort); - g_assert_cmphex(sz, =3D=3D, 0xfffffffffffff800); - visit_type_size(v, "sz2", &sz, &error_abort); - g_assert_cmphex(sz, =3D=3D, 0xfffffffffffff800); + g_assert_cmphex(sz, =3D=3D, 0xffffffffffffffff); visit_check_struct(v, &error_abort); visit_end_struct(v, NULL); visit_free(v); =20 /* Beyond limits */ qdict =3D keyval_parse("sz1=3D-1," - "sz2=3D18446744073709550592", /* fffffffffffffc00= */ + "sz2=3D18446744073709551616", /* 2^64 */ NULL, &error_abort); v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index ef96e84aed..1236bf6b7d 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -650,50 +650,25 @@ static void test_opts_parse_size(void) g_assert_cmpuint(opts_count(opts), =3D=3D, 1); g_assert_cmpuint(qemu_opt_get_size(opts, "size1", 1), =3D=3D, 0); =20 - /* Note: precision is 53 bits since we're parsing with strtod() */ + /* Note: precision is 64 bits (UINT64_MAX) */ =20 - /* Around limit of precision: 2^53-1, 2^53, 2^54 */ + /* Around limit of precision: UINT64_MAX - 1, UINT64_MAX */ opts =3D qemu_opts_parse(&opts_list_02, - "size1=3D9007199254740991," - "size2=3D9007199254740992," - "size3=3D9007199254740993", - false, &error_abort); - g_assert_cmpuint(opts_count(opts), =3D=3D, 3); - g_assert_cmphex(qemu_opt_get_size(opts, "size1", 1), - =3D=3D, 0x1fffffffffffff); - g_assert_cmphex(qemu_opt_get_size(opts, "size2", 1), - =3D=3D, 0x20000000000000); - g_assert_cmphex(qemu_opt_get_size(opts, "size3", 1), - =3D=3D, 0x20000000000000); - - /* Close to signed upper limit 0x7ffffffffffffc00 (53 msbs set) */ - opts =3D qemu_opts_parse(&opts_list_02, - "size1=3D9223372036854774784," /* 7ffffffffffff= c00 */ - "size2=3D9223372036854775295", /* 7ffffffffffff= dff */ - false, &error_abort); - g_assert_cmpuint(opts_count(opts), =3D=3D, 2); - g_assert_cmphex(qemu_opt_get_size(opts, "size1", 1), - =3D=3D, 0x7ffffffffffffc00); - g_assert_cmphex(qemu_opt_get_size(opts, "size2", 1), - =3D=3D, 0x7ffffffffffffc00); - - /* Close to actual upper limit 0xfffffffffffff800 (53 msbs set) */ - opts =3D qemu_opts_parse(&opts_list_02, - "size1=3D18446744073709549568," /* ffffffffffff= f800 */ - "size2=3D18446744073709550591", /* ffffffffffff= fbff */ + "size1=3D18446744073709551614," + "size2=3D18446744073709551615", false, &error_abort); g_assert_cmpuint(opts_count(opts), =3D=3D, 2); g_assert_cmphex(qemu_opt_get_size(opts, "size1", 1), - =3D=3D, 0xfffffffffffff800); + =3D=3D, 0xfffffffffffffffe); g_assert_cmphex(qemu_opt_get_size(opts, "size2", 1), - =3D=3D, 0xfffffffffffff800); + =3D=3D, 0xffffffffffffffff); =20 /* Beyond limits */ opts =3D qemu_opts_parse(&opts_list_02, "size1=3D-1", false, &err); error_free_or_abort(&err); g_assert(!opts); opts =3D qemu_opts_parse(&opts_list_02, - "size1=3D18446744073709550592", /* ffffffffffff= fc00 */ + "size1=3D18446744073709551616", /* 2^64 */ false, &err); error_free_or_abort(&err); g_assert(!opts); diff --git a/util/cutils.c b/util/cutils.c index 5db3b2add5..d94a468954 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -216,13 +216,13 @@ static int do_strtosz(const char *nptr, const char **= end, const char *endptr; unsigned char c; int mul_required =3D 0; - double val, mul, integral, fraction; + long double val, mul, integral, fraction; =20 - retval =3D qemu_strtod_finite(nptr, &endptr, &val); + retval =3D qemu_strtold_finite(nptr, &endptr, &val); if (retval) { goto out; } - fraction =3D modf(val, &integral); + fraction =3D modfl(val, &integral); if (fraction !=3D 0) { mul_required =3D 1; } @@ -238,11 +238,8 @@ static int do_strtosz(const char *nptr, const char **e= nd, retval =3D -EINVAL; goto out; } - /* - * Values >=3D 0xfffffffffffffc00 overflow uint64_t after their trip - * through double (53 bits of precision). - */ - if ((val * mul >=3D 0xfffffffffffffc00) || val < 0) { + /* Values > UINT64_MAX overflow uint64_t */ + if ((val * mul > UINT64_MAX) || val < 0) { retval =3D -ERANGE; goto out; } --=20 2.20.1 From nobody Wed May 1 00:40:29 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=1574409181; cv=none; d=zoho.com; s=zohoarc; b=oXJ+VyYjlvD9HreVzoqvLt/hm6jKxSFQvsD3JGQisNl3/HGdf5o5P8nZXobDgoQ8SBS6nlylRMjCPko7FvkCXu/WOthIJzY5pPuM7aFaMJ7S2yacXOAmWVH8AK1PL5y04to6XyVQtia7KvSHccwIqqr8Hay5fjcEDi4eKpS4Paw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409181; 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; bh=chaRy2olui6w6LMUBGydu+V+TUVLG+tEifFIJj6MUoA=; b=g1h9Wkvo2Jvcn5yIya5CVEjT7VnR09m3SmH6BHiIq3wMMo7vfAbjXhDNXOg5e7dxocDWXkkAQcHPrFxjky/1Zn9B+h9aO3HpKhdSvSQQzuaDWwIZmyPFRwDocjcgnrXCpu6CmXLwtq+sDJcEgvIppYWRYCfujFHlcHs85rjjsXA= 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 1574409181697218.22412079437981; Thu, 21 Nov 2019 23:53:01 -0800 (PST) Received: from localhost ([::1]:47970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3kP-0001W3-SY for importer@patchew.org; Fri, 22 Nov 2019 02:52:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39468) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gI-0005Fp-Tl for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gH-0002m2-Ia for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:42 -0500 Received: from mga18.intel.com ([134.134.136.126]:36761) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gH-0002i6-8x for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:41 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:48:40 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:48:38 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178468" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 03/14] util/cutils: refactor do_strtosz() to support suffixes list Date: Fri, 22 Nov 2019 15:48:15 +0800 Message-Id: <20191122074826.1373-4-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add do_strtomul() to convert string according to different suffixes. Reviewed-by: Eduardo Habkost Signed-off-by: Tao Xu --- No changes in v17. Changes in v15: - Add a new patch to refactor do_strtosz() (Eduardo) --- util/cutils.c | 72 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/util/cutils.c b/util/cutils.c index d94a468954..ffef92338a 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -181,41 +181,37 @@ int fcntl_setfl(int fd, int flag) } #endif =20 -static int64_t suffix_mul(char suffix, int64_t unit) +static int64_t suffix_mul(const char *suffixes[], int num_suffix, + const char *endptr, int *offset, int64_t unit) { - switch (qemu_toupper(suffix)) { - case 'B': - return 1; - case 'K': - return unit; - case 'M': - return unit * unit; - case 'G': - return unit * unit * unit; - case 'T': - return unit * unit * unit * unit; - case 'P': - return unit * unit * unit * unit * unit; - case 'E': - return unit * unit * unit * unit * unit * unit; + int i, suffix_len; + int64_t mul =3D 1; + + for (i =3D 0; i < num_suffix; i++) { + suffix_len =3D strlen(suffixes[i]); + if (g_ascii_strncasecmp(suffixes[i], endptr, suffix_len) =3D=3D 0)= { + *offset =3D suffix_len; + return mul; + } + mul *=3D unit; } + return -1; } =20 /* - * Convert string to bytes, allowing either B/b for bytes, K/k for KB, - * M/m for MB, G/g for GB or T/t for TB. End pointer will be returned - * in *end, if not NULL. Return -ERANGE on overflow, and -EINVAL on - * other error. + * Convert string according to different suffixes. End pointer will be ret= urned + * in *end, if not NULL. Return -ERANGE on overflow, and -EINVAL on other = error. */ -static int do_strtosz(const char *nptr, const char **end, - const char default_suffix, int64_t unit, +static int do_strtomul(const char *nptr, const char **end, + const char *suffixes[], int num_suffix, + const char *default_suffix, int64_t unit, uint64_t *result) { int retval; const char *endptr; - unsigned char c; int mul_required =3D 0; + int offset =3D 0; long double val, mul, integral, fraction; =20 retval =3D qemu_strtold_finite(nptr, &endptr, &val); @@ -226,12 +222,12 @@ static int do_strtosz(const char *nptr, const char **= end, if (fraction !=3D 0) { mul_required =3D 1; } - c =3D *endptr; - mul =3D suffix_mul(c, unit); + + mul =3D suffix_mul(suffixes, num_suffix, endptr, &offset, unit); if (mul >=3D 0) { - endptr++; + endptr +=3D offset; } else { - mul =3D suffix_mul(default_suffix, unit); + mul =3D suffix_mul(suffixes, num_suffix, default_suffix, &offset, = unit); assert(mul >=3D 0); } if (mul =3D=3D 1 && mul_required) { @@ -256,19 +252,35 @@ out: return retval; } =20 +/* + * Convert string to bytes, allowing either B/b for bytes, K/k for KB, + * M/m for MB, G/g for GB or T/t for TB. End pointer will be returned + * in *end, if not NULL. Return -ERANGE on overflow, and -EINVAL on + * other error. + */ +static int do_strtosz(const char *nptr, const char **end, + const char *default_suffix, int64_t unit, + uint64_t *result) +{ + static const char *suffixes[] =3D { "B", "K", "M", "G", "T", "P", "E" = }; + + return do_strtomul(nptr, end, suffixes, ARRAY_SIZE(suffixes), + default_suffix, unit, result); +} + int qemu_strtosz(const char *nptr, const char **end, uint64_t *result) { - return do_strtosz(nptr, end, 'B', 1024, result); + return do_strtosz(nptr, end, "B", 1024, result); } =20 int qemu_strtosz_MiB(const char *nptr, const char **end, uint64_t *result) { - return do_strtosz(nptr, end, 'M', 1024, result); + return do_strtosz(nptr, end, "M", 1024, result); } =20 int qemu_strtosz_metric(const char *nptr, const char **end, uint64_t *resu= lt) { - return do_strtosz(nptr, end, 'B', 1000, result); + return do_strtosz(nptr, end, "B", 1000, result); } =20 /** --=20 2.20.1 From nobody Wed May 1 00:40:29 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=1574409039; cv=none; d=zoho.com; s=zohoarc; b=cJG3wkrO1AoaEgOL4r6ddRBYl/Bcd2fHZyO7yO4w5LqJe5kDzEIQqLivheeiJPcY7vSe8H3UVvzGS1J32TTtkulxi/DRV7QdGRW0yz+KfjVtF026j240uehv2bRJgPwCdFJ9ki5/s8O3bfCPk9UGRSS7zkxy8Bfv7JrFbs2yq+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409039; 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; bh=NGR2VqrIj0xvLLWFFruFZVAg75nR7Ju8wpIdfW/wJbs=; b=BpR8+NwhrZ3HqwqFlcdd30+aux8G3NYBmz98OVw5OCFDt8HkFisdyXaQPKhHPGtaRxrLIDjZeDp3M64ofEu41Tcgig0XCOeqzyOVfKi7nUkBWtQb+u//1p3kYj6J0dGp23KpPjh9b0QsmWnIjhWW9qucHD0JmEOkvgh1aUi/9IQ= 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 1574409039157393.7580191257557; Thu, 21 Nov 2019 23:50:39 -0800 (PST) Received: from localhost ([::1]:47946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3i9-0006ww-PX for importer@patchew.org; Fri, 22 Nov 2019 02:50:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39505) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gM-0005Ke-R9 for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gL-0002n8-1N for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:46 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gK-0002kF-NL for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:44 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:48:44 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:48:41 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178481" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 04/14] util/cutils: Add qemu_strtotime_ns() Date: Fri, 22 Nov 2019 15:48:16 +0800 Message-Id: <20191122074826.1373-5-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 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 "ns" for nanosecond, "us" for microsecond, "ms" for millisecond or "s" for second. Add test for qemu_strtotime_ns, test the input of basic, time suffixes, float, invaild, trailing and overflow. Reviewed-by: Eduardo Habkost Signed-off-by: Tao Xu --- No changes in v17. Changes in v16: - Update the test because precision is 64 bits Changes in v15: - Add a new patch to refactor do_strtosz() (Eduardo) - use ARRAY_SIZE(suffixes) instead of hardcoding the suffixes number (Eduardo) --- include/qemu/cutils.h | 1 + tests/test-cutils.c | 173 ++++++++++++++++++++++++++++++++++++++++++ util/cutils.c | 14 ++++ 3 files changed, 188 insertions(+) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 48cf9bf776..befa94f2d4 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -185,5 +185,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_ns(const char *nptr, const char **end, uint64_t *result= ); =20 #endif diff --git a/tests/test-cutils.c b/tests/test-cutils.c index 465514b85f..0ff1d816f1 100644 --- a/tests/test-cutils.c +++ b/tests/test-cutils.c @@ -2148,6 +2148,167 @@ static void test_qemu_strtosz_metric(void) g_assert(endptr =3D=3D str + 6); } =20 +static void test_qemu_strtotime_ns_simple(void) +{ + const char *str; + const char *endptr; + int err; + uint64_t res =3D 0xbaadf00d; + + str =3D "0"; + err =3D qemu_strtotime_ns(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_ns(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_ns(str, NULL, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 56789); + + /* Note: precision is 64 bits (UINT64_MAX) */ + + str =3D "18446744073709551614"; /* UINT64_MAX - 1 */ + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 0xfffffffffffffffe); + g_assert(endptr =3D=3D str + 20); + + str =3D "18446744073709551615"; /* UINT64_MAX */ + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 0xffffffffffffffff); + g_assert(endptr =3D=3D str + 20); +} + +static void test_qemu_strtotime_ns_units(void) +{ + 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; + + /* default time unit is ns */ + err =3D qemu_strtotime_ns(ns, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 1); + g_assert(endptr =3D=3D ns + 3); + + err =3D qemu_strtotime_ns(us, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 1000); + g_assert(endptr =3D=3D us + 3); + + err =3D qemu_strtotime_ns(ms, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 1000000); + g_assert(endptr =3D=3D ms + 3); + + err =3D qemu_strtotime_ns(s, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 1000000000LL); + g_assert(endptr =3D=3D s + 2); +} + +static void test_qemu_strtotime_ns_float(void) +{ + const char *str =3D "56.789us"; + int err; + const char *endptr; + uint64_t res =3D 0xbaadf00d; + + err =3D qemu_strtotime_ns(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_ns_invalid(void) +{ + const char *str; + const char *endptr; + int err; + uint64_t res =3D 0xbaadf00d; + + str =3D ""; + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + g_assert(endptr =3D=3D str); + + str =3D " \t "; + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + g_assert(endptr =3D=3D str); + + str =3D "crap"; + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + g_assert(endptr =3D=3D str); + + str =3D "inf"; + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + g_assert(endptr =3D=3D str); + + str =3D "NaN"; + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + g_assert(endptr =3D=3D str); +} + +static void test_qemu_strtotime_ns_trailing(void) +{ + const char *str; + const char *endptr; + int err; + uint64_t res =3D 0xbaadf00d; + + str =3D "123xxx"; + + err =3D qemu_strtotime_ns(str, NULL, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); + + str =3D "1msxxx"; + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, 0); + g_assert_cmpint(res, =3D=3D, 1000000); + g_assert(endptr =3D=3D str + 3); + + err =3D qemu_strtotime_ns(str, NULL, &res); + g_assert_cmpint(err, =3D=3D, -EINVAL); +} + +static void test_qemu_strtotime_ns_erange(void) +{ + const char *str; + const char *endptr; + int err; + uint64_t res =3D 0xbaadf00d; + + str =3D "-1"; + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -ERANGE); + g_assert(endptr =3D=3D str + 2); + + str =3D "18446744073709551616"; /* 2^64 */ + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -ERANGE); + g_assert(endptr =3D=3D str + 20); + + str =3D "200000000000000ms"; + err =3D qemu_strtotime_ns(str, &endptr, &res); + g_assert_cmpint(err, =3D=3D, -ERANGE); + g_assert(endptr =3D=3D str + 17); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -2425,5 +2586,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_ns_simple); + g_test_add_func("/cutils/strtotime/units", + test_qemu_strtotime_ns_units); + g_test_add_func("/cutils/strtotime/float", + test_qemu_strtotime_ns_float); + g_test_add_func("/cutils/strtotime/invalid", + test_qemu_strtotime_ns_invalid); + g_test_add_func("/cutils/strtotime/trailing", + test_qemu_strtotime_ns_trailing); + g_test_add_func("/cutils/strtotime/erange", + test_qemu_strtotime_ns_erange); return g_test_run(); } diff --git a/util/cutils.c b/util/cutils.c index ffef92338a..0a885a0a90 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -283,6 +283,20 @@ int qemu_strtosz_metric(const char *nptr, const char *= *end, uint64_t *result) return do_strtosz(nptr, end, "B", 1000, result); } =20 +/* + * Convert string to time, support time unit are ns for nanosecond, us for + * microsecond, ms for millisecond and s for second. End pointer will be + * returned in *end, if not NULL. Return -ERANGE on overflow, and -EINVAL = on + * other error. + */ +int qemu_strtotime_ns(const char *nptr, const char **end, uint64_t *result) +{ + static const char *suffixes[] =3D { "ns", "us", "ms", "s" }; + + return do_strtomul(nptr, end, suffixes, ARRAY_SIZE(suffixes), "ns", 10= 00, + result); +} + /** * Helper function for error checking after strtol() and the like */ --=20 2.20.1 From nobody Wed May 1 00:40:29 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=1574409407; cv=none; d=zoho.com; s=zohoarc; b=hrSCZAyZTOKq+X0clxoMz4E8vO5XcixC+m6+AR4l9PM7QA+MNIpBNJAqKXDU12z0j+A5LJdaoGCnQyqcsj8nSs25IU/WqjuzhIMb6ru5RD8V9aVXnZm2Mx1LdeYUwsvgFsNP8GCPn8vF7ekMBvwVTk3tjIJRxQhnHHswvJblADA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409407; 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; bh=r2bwSws4vOx7WntsZiYXLDrkLa+h9eEFXSyAf6vtUiU=; b=SRAMqVq1koLLPARAe69HkYHiIF5HYrwzpSK/cil0kr9WcQlPnOzuyzof4DCboaokjkhEyuqinRSCv48hoaeb3DeCy+MziEyB1rC0pB+b8hTHnuE4tZpBySlFYhssOfvwb8+6vy0VCJ0kuWpOa2tVYxTastRyXCfBQc2G61P0yJI= 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 1574409407967130.65123468795332; Thu, 21 Nov 2019 23:56:47 -0800 (PST) Received: from localhost ([::1]:48028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3o6-0005uv-Gf for importer@patchew.org; Fri, 22 Nov 2019 02:56:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39519) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gQ-0005PP-4z for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gO-0002nw-Fq for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:49 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gO-0002kF-46 for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:48 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:48:47 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:48:44 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178498" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 05/14] qapi: Add builtin type time Date: Fri, 22 Nov 2019 15:48:17 +0800 Message-Id: <20191122074826.1373-6-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 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_ns() for pre-converting time suffix to numbers. Signed-off-by: Tao Xu --- No changes in v17. Changes in v14: - Drop time unit picosecond (Eric) --- include/qapi/visitor-impl.h | 4 ++++ include/qapi/visitor.h | 8 ++++++++ qapi/opts-visitor.c | 22 ++++++++++++++++++++++ qapi/qapi-visit-core.c | 12 ++++++++++++ qapi/qobject-input-visitor.c | 18 ++++++++++++++++++ qapi/trace-events | 1 + scripts/qapi/schema.py | 1 + 7 files changed, 66 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 c5b23851a1..22242e706f 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -554,6 +554,14 @@ 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 "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 5fe0276c1c..59b575f0fc 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -526,6 +526,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_ns(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) @@ -573,6 +594,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..e476fe0d16 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_ns(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/schema.py b/scripts/qapi/schema.py index cf0045f34e..210be64909 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -855,6 +855,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 Wed May 1 00:40:29 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=1574409209; cv=none; d=zoho.com; s=zohoarc; b=lwv6W+ejN+ACdENpwnNd6YD6cq11zCvPS69ixfL/3B6Aogr2wrQCUSvDhk+uAUNg1Mnur2sVYpIFbCPo0rCW68lOn1PUaMyE4pnxSGIVncnuSxwpwS1Pxivx54POSo+JJ8QmnZVSIGY/T9GvAIJVgGkBTF+3Dowrdnv1GxSSviQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409209; 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; bh=91pP2i2uoRkU7ju937j1qRv6vf39iAcU3cuwvks8+gk=; b=P/dclAm9/7e4ODPKEYctcBlGVYvfTA76vrmdSJwH4wzRtTDfHEndvs8Qc+9iVaNi4B0kEwwesAz5QUzF+IaceLKqhyBlUk3znlu5nEN4wKe+9YCDtVzgwjdhV8QlxN41LKCovsg8H9nTxP4CXlkq5TilZwzkCy+Jpf/r9R/Qvr0= 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 1574409209890952.1191130523584; Thu, 21 Nov 2019 23:53:29 -0800 (PST) Received: from localhost ([::1]:47976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3kt-0002L2-T3 for importer@patchew.org; Fri, 22 Nov 2019 02:53:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39536) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gS-0005Tv-T4 for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gR-0002op-F8 for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:52 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gR-0002kF-7M for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:51 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:48:50 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:48:47 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178509" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 06/14] tests: Add test for QAPI builtin type time Date: Fri, 22 Nov 2019 15:48:18 +0800 Message-Id: <20191122074826.1373-7-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 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 v17. Changes in v16: - Update the test cases Changes in v14: - Drop time unit picosecond (Eric) --- tests/test-keyval.c | 89 ++++++++++++++++++++++++++++++ tests/test-qobject-input-visitor.c | 29 ++++++++++ 2 files changed, 118 insertions(+) diff --git a/tests/test-keyval.c b/tests/test-keyval.c index fad941fcb8..39443f7e0c 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -457,6 +457,94 @@ 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: UINT64_MAX - 1, UINT64_MAX */ + qdict =3D keyval_parse("time1=3D18446744073709551614," + "time2=3D18446744073709551615", + 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, 0xfffffffffffffffe); + visit_type_time(v, "time2", &time, &error_abort); + g_assert_cmphex(time, =3D=3D, 0xffffffffffffffff); + visit_check_struct(v, &error_abort); + visit_end_struct(v, NULL); + visit_free(v); + + /* Beyond limits */ + qdict =3D keyval_parse("time1=3D-1," + "time2=3D18446744073709551616", /* 2^64 */ + 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=3D2ns,time2=3D3.4us,time3=3D5ms,time4=3D= 600s", + 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 * 1000000000LL); + visit_check_struct(v, &error_abort); + visit_end_struct(v, NULL); + visit_free(v); + + /* Beyond limit with suffix */ + qdict =3D keyval_parse("time1=3D1844674407370955s", 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; @@ -645,6 +733,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..55138042b8 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, "\"265ms\""); + + 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, "\"265ms\""); + + 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 Wed May 1 00:40:29 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=1574409545; cv=none; d=zoho.com; s=zohoarc; b=PSjjQmr/ljjeXx+1/HPwIr8FQ+pOo0e8YypGeE8YIEyEx2Uj0JdXsPRR9UMVhros9LKjMMpgVnIVmalXwUGZhEIQ3iw7iTqhK0SEQ8tc4ja+22AxJ+WTgFbZX2wPAM5TAIskzLOA8e/CxG6GJC8y3aN0dPTthHmBal9yluyerEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409545; 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; bh=U098zD9xxRSz1uHhHgIIKU/g2fnKqlkMqXrsx35rPJs=; b=lugJV2DEH1qSRp3/vDurk6EUiMPlT6jAoyc853VszuhTxE2K7rcFiReyjUnxujeTqd35QhBB/7v7UzBhoxwhmV9WEM6MdMgW6IMd18zzkAkBlxE/MkdUEbh+S2WlG0f9bzmmzd6fBr+2faHy14CXj/hVU5CwMdJY26/KThhJKYQ= 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 1574409545296576.746189328117; Thu, 21 Nov 2019 23:59:05 -0800 (PST) Received: from localhost ([::1]:48068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3qJ-0000SP-4S for importer@patchew.org; Fri, 22 Nov 2019 02:59:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39553) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gX-0005bD-7W for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gV-0002pi-5v for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:57 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gU-0002kF-Ow for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:55 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:48:54 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:48:51 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178519" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 07/14] numa: Extend CLI to provide initiator information for numa nodes Date: Fri, 22 Nov 2019 15:48:19 +0800 Message-Id: <20191122074826.1373-8-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 Williams 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. Reviewed-by: Igor Mammedov Reviewed-by: Jingqi Liu Suggested-by: Dan Williams Signed-off-by: Tao Xu --- No changes in v17. Changes in v15: - Change the QAPI version tag to 5.0 (Eric) --- hw/core/machine.c | 64 +++++++++++++++++++++++++++++++++++++++++++ hw/core/numa.c | 23 ++++++++++++++++ include/sysemu/numa.h | 5 ++++ qapi/machine.json | 10 ++++++- qemu-options.hx | 35 +++++++++++++++++++---- 5 files changed, 131 insertions(+), 6 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 1689ad3bf8..d7d2cfa66d 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,17 @@ 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 (machine->numa_state->hmat_enabled) { + if ((numa_info[props->node_id].initiator < MAX_NODES) && + (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].has_cpu =3D true; + numa_info[props->node_id].initiator =3D props->node_id; + } } =20 if (!match) { @@ -960,6 +986,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 +1081,32 @@ static char *cpu_slot_to_string(const CPUArchId *cpu) return g_string_free(s, false); } =20 +static void numa_validate_initiator(NumaState *numa_state) +{ + int i; + NodeInfo *numa_info =3D numa_state->nodes; + + for (i =3D 0; i < numa_state->num_nodes; i++) { + if (numa_info[i].initiator =3D=3D MAX_NODES) { + error_report("The initiator of NUMA node %d is missing, use " + "'-numa node,initiator' option to declare it", i); + exit(1); + } + + 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); + exit(1); + } + + if (!numa_info[numa_info[i].initiator].has_cpu) { + error_report("The initiator of NUMA node %d is invalid", i); + exit(1); + } + } +} + static void machine_numa_finish_cpu_init(MachineState *machine) { int i; @@ -1088,6 +1147,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 e3332a984f..e60da99293 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -133,6 +133,29 @@ 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 not set the initiator, set it to MAX_NODES. And if + * HMAT is enabled and this node has no cpus, QEMU will raise error. + */ + numa_info[nodenr].initiator =3D MAX_NODES; + if (node->has_initiator) { + if (!ms->numa_state->hmat_enabled) { + error_setg(errp, "ACPI Heterogeneous Memory Attribute Table " + "(HMAT) is disabled, enable it with -machine hmat= =3Don " + "before using any of hmat specific options"); + return; + } + + if (node->initiator >=3D MAX_NODES) { + error_report("The initiator id %" PRIu16 " expects an integer " + "between 0 and %d", node->initiator, + MAX_NODES - 1); + 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..788cbec7a2 100644 --- a/include/sysemu/numa.h +++ b/include/sysemu/numa.h @@ -18,6 +18,8 @@ struct NodeInfo { uint64_t node_mem; struct HostMemoryBackend *node_memdev; bool present; + bool has_cpu; + uint16_t initiator; uint8_t distance[MAX_NODES]; }; =20 @@ -33,6 +35,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..27d0e37534 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, +# points to 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 5.0) +# # 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 65c9473b73..63f6b33322 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 that points to an @var{initiator} +NUMA node that has best performance (the lowest latency or largest bandwid= th) +to this NUMA @var{node}. Note that this option can be set only when +the machine property 'hmat' is set to 'on'. + +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 Wed May 1 00:40:29 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=1574409199; cv=none; d=zoho.com; s=zohoarc; b=Oy0b5JYNCRmE0gtSOJVHMQ6WYTA2GqGZ8Tt5AanP9FW/T/j3z2PDtH7ltRdJuQ0ss2Endu+KPYl7QzEUw4EOwfzfIu0qfgu+xkkIQSL4Q/fgkHaPYu0AQhGixZtIxtFX5m9SHEId0BS7D33zrivbHah3bmcMAHsAnr9nr1fuQ7w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409199; 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; bh=skRIwmpalt7uI8gBIz5+EEPCv2DcL/DpX/PvSHKGUtQ=; b=L/5PY8ZTks2R2GaTKfwhe3ZfN19IK24EyhBVKlV1wl5MPo5M6hrf/skPLvRazDiEZ20N+7imGGsYYt70GshdBi9uGjta3erFtVXneka/r1cj2EpKQdYnHKpxoO+4EaVLmPs+SRvE8QMp5leBM7yJaHNqVNltxnFhM+NxyZwFtfk= 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 1574409199925491.4156885624948; Thu, 21 Nov 2019 23:53:19 -0800 (PST) Received: from localhost ([::1]:47972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3ki-00021l-M6 for importer@patchew.org; Fri, 22 Nov 2019 02:53:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39566) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gb-0005hi-4z for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gY-0002rw-KN for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:01 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gX-0002kF-UH for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:48:58 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:48:57 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:48:54 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178531" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 08/14] numa: Extend CLI to provide memory latency and bandwidth information Date: Fri, 22 Nov 2019 15:48:20 +0800 Message-Id: <20191122074826.1373-9-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 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). Reviewed-by: Igor Mammedov Signed-off-by: Liu Jingqi Signed-off-by: Tao Xu --- Changes in v17: - Add check when user input latency or bandwidth 0, the lb_info_provided should also be 0. Because in ACPI 6.3 5.2.27.4, 0 means the corresponding latency or bandwidth information is not provided. - Fix the infinite loop when node->latency is 0. Changes in v16: - Initialize HMAT_LB_Data lb_data (Igor) - Remove punctuation from error_setg (Igor) - Correct some description (Igor) - Drop statement about max value (Igor) - Simplify struct HMAT_LB_Info and related code, unify latency and bandwidth (Igor) Changes in v15: - Change the QAPI version tag to 5.0 (Eric) --- hw/core/numa.c | 178 ++++++++++++++++++++++++++++++++++++++++++ include/sysemu/numa.h | 53 +++++++++++++ qapi/machine.json | 94 +++++++++++++++++++++- qemu-options.hx | 49 +++++++++++- 4 files changed, 371 insertions(+), 3 deletions(-) diff --git a/hw/core/numa.c b/hw/core/numa.c index e60da99293..70bc8a1081 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -23,6 +23,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/units.h" #include "sysemu/hostmem.h" #include "sysemu/numa.h" #include "sysemu/sysemu.h" @@ -198,6 +199,170 @@ 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 *numa_state, NumaHmatLBOptions *node, + Error **errp) +{ + int i, first_bit, last_bit; + uint64_t max_entry, temp_base_la; + NodeInfo *numa_info =3D numa_state->nodes; + HMAT_LB_Info *hmat_lb =3D + numa_state->hmat_lb[node->hierarchy][node->data_type]; + HMAT_LB_Data lb_data =3D {}; + HMAT_LB_Data *lb_temp; + + /* Error checking */ + if (node->initiator > numa_state->num_nodes) { + error_setg(errp, "Invalid initiator=3D%d, it should be less than %= d", + node->initiator, numa_state->num_nodes); + return; + } + if (node->target > numa_state->num_nodes) { + error_setg(errp, "Invalid target=3D%d, it should be less than %d", + node->target, numa_state->num_nodes); + return; + } + if (!numa_info[node->initiator].has_cpu) { + error_setg(errp, "Invalid initiator=3D%d, it isn't an " + "initiator proximity domain", node->initiator); + return; + } + if (!numa_info[node->target].present) { + error_setg(errp, "The target=3D%d should point to an existing node= ", + node->target); + return; + } + + if (!hmat_lb) { + hmat_lb =3D g_malloc0(sizeof(*hmat_lb)); + numa_state->hmat_lb[node->hierarchy][node->data_type] =3D hmat_lb; + hmat_lb->list =3D g_array_new(false, true, sizeof(HMAT_LB_Data)); + } + hmat_lb->hierarchy =3D node->hierarchy; + hmat_lb->data_type =3D node->data_type; + lb_data.initiator =3D node->initiator; + lb_data.target =3D node->target; + + if (node->data_type <=3D HMATLB_DATA_TYPE_WRITE_LATENCY) { + /* Input latency data */ + + 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; + } + + /* Detect duplicate configuration */ + for (i =3D 0; i < hmat_lb->list->len; i++) { + lb_temp =3D &g_array_index(hmat_lb->list, HMAT_LB_Data, i); + + if (node->initiator =3D=3D lb_temp->initiator && + node->target =3D=3D lb_temp->target) { + error_setg(errp, "Duplicate configuration of the latency f= or " + "initiator=3D%d and target=3D%d", node->initiator, + node->target); + return; + } + } + + hmat_lb->base =3D hmat_lb->base ? hmat_lb->base : UINT64_MAX; + + if (node->latency) { + /* Calculate the temporary base and compressed latency */ + max_entry =3D node->latency; + temp_base_la =3D 1; + while (QEMU_IS_ALIGNED(max_entry, 10)) { + max_entry /=3D 10; + temp_base_la *=3D 10; + } + + /* Calculate the max compressed latency */ + hmat_lb->base =3D MIN(hmat_lb->base, temp_base_la); + max_entry =3D node->latency / hmat_lb->base; + hmat_lb->range_bitmap =3D MAX(hmat_lb->range_bitmap, max_entry= ); + + /* + * For latency hmat_lb->range_bitmap record the max compressed + * latency which should be less than 0xFFFF (UINT16_MAX) + */ + if (hmat_lb->range_bitmap >=3D UINT16_MAX) { + error_setg(errp, "Latency %" PRIu64 " between initiator=3D= %d and " + "target=3D%d should not differ from previously ent= ered " + "min or max values on more than %d", node->latency, + node->initiator, node->target, UINT16_MAX - 1); + return; + } + + /* Set lb_info_provided bit 0 as 1, latency information is pro= vided */ + numa_info[node->target].lb_info_provided |=3D BIT(0); + } + lb_data.data =3D node->latency; + } else if (node->data_type >=3D HMATLB_DATA_TYPE_ACCESS_BANDWIDTH) { + /* Input bandwidth data */ + + 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 (!QEMU_IS_ALIGNED(node->bandwidth, MiB)) { + error_setg(errp, "Bandwidth %" PRIu64 " between initiator=3D%d= and " + "target=3D%d should be 1MB aligned", node->bandwidt= h, + node->initiator, node->target); + return; + } + + /* Detect duplicate configuration */ + for (i =3D 0; i < hmat_lb->list->len; i++) { + lb_temp =3D &g_array_index(hmat_lb->list, HMAT_LB_Data, i); + + if (node->initiator =3D=3D lb_temp->initiator && + node->target =3D=3D lb_temp->target) { + error_setg(errp, "Duplicate configuration of the bandwidth= for " + "initiator=3D%d and target=3D%d", node->initiator, + node->target); + return; + } + } + + hmat_lb->range_bitmap |=3D node->bandwidth; + first_bit =3D ctz64(hmat_lb->range_bitmap); + hmat_lb->base =3D UINT64_C(1) << first_bit; + max_entry =3D node->bandwidth / hmat_lb->base; + last_bit =3D 64 - clz64(hmat_lb->range_bitmap); + + /* + * For bandwidth, first_bit record the base unit of bandwidth bits, + * last_bit record the last bit of the max bandwidth. The max comp= ressed + * bandwidth should be less than 0xFFFF (UINT16_MAX) + */ + if ((last_bit - first_bit) > UINT16_BITS || max_entry >=3D UINT16_= MAX) { + error_setg(errp, "Bandwidth %" PRIu64 " between initiator=3D%d= and " + "target=3D%d should not differ from previously ente= red " + "values on more than %d", node->bandwidth, + node->initiator, node->target, UINT16_MAX - 1); + return; + } + + /* Set lb_info_provided bit 1 as 1, bandwidth information is provi= ded */ + if (node->bandwidth) { + numa_info[node->target].lb_info_provided |=3D BIT(1); + } + lb_data.data =3D node->bandwidth; + } else { + assert(0); + } + + g_array_append_val(hmat_lb->list, lb_data); +} + void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp) { Error *err =3D NULL; @@ -236,6 +401,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, enable it with -machine hmat= =3Don " + "before using any of hmat specific options"); + return; + } + + parse_numa_hmat_lb(ms->numa_state, &object->u.hmat_lb, &err); + if (err) { + goto end; + } + break; default: abort(); } diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h index 788cbec7a2..70f93c83d7 100644 --- a/include/sysemu/numa.h +++ b/include/sysemu/numa.h @@ -14,11 +14,34 @@ 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, + HMAT_LB_LEVELS /* must be the last entry */ +}; + +/* 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, + HMAT_LB_TYPES /* must be the last entry */ +}; + +#define UINT16_BITS 16 + struct NodeInfo { uint64_t node_mem; struct HostMemoryBackend *node_memdev; bool present; bool has_cpu; + uint8_t lb_info_provided; uint16_t initiator; uint8_t distance[MAX_NODES]; }; @@ -28,6 +51,31 @@ struct NumaNodeMem { uint64_t node_plugged_mem; }; =20 +struct HMAT_LB_Data { + uint8_t initiator; + uint8_t target; + uint64_t data; +}; +typedef struct HMAT_LB_Data HMAT_LB_Data; + +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; + + /* The range bitmap of bandwidth for calculating common base */ + uint64_t range_bitmap; + + /* The common base unit for latencies or bandwidths */ + uint64_t base; + + /* Array to store the latencies or bandwidths */ + GArray *list; +}; +typedef struct HMAT_LB_Info HMAT_LB_Info; + struct NumaState { /* Number of NUMA nodes */ int num_nodes; @@ -40,11 +88,16 @@ struct NumaState { =20 /* 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 *numa_state, 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 27d0e37534..67f5910400 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: 5.0) +# # 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,93 @@ '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 about @HmatLBMemoryHierarchy see +# the chapter 5.2.27.4: Table 5-146: Field "Flags" of ACPI 6.3 spec. +# +# @memory: the structure represents the memory performance +# +# @first-level: first level of memory side cache +# +# @second-level: second level of memory side cache +# +# @third-level: third level of memory side cache +# +# Since: 5.0 +## +{ '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 about @HmatLBDataType see +# the chapter 5.2.27.4: Table 5-146: 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 (B/s) +# +# @read-bandwidth: read bandwidth (B/s) +# +# @write-bandwidth: write bandwidth (B/s) +# +# Since: 5.0 +## +{ '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 about @NumaHmatLBOptions see +# the chapter 5.2.27.4: Table 5-146 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 unit is "ns(nanosecond)". +# +# @bandwidth: the value of bandwidth between @initiator and @target proxim= ity +# domain, the bandwidth unit is "B(/s)". +# +# Since: 5.0 +## +{ '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 63f6b33322..929d275450 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{hierarchy},data-type=3D@var{tpye}[,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 it has one or more= processors. +Target NUMA node contains addressable memory. + +In @samp{hmat-lb} option, @var{node} are NUMA node IDs. @var{hierarchy} is= the memory +hierarchy of the target NUMA node: if @var{hierarchy} is 'memory', the str= ucture +represents the memory performance; if @var{hierarchy} is 'first-level|seco= nd-level|third-level', +this structure represents aggregated performance of memory side caches for= each domain. +@var{type} of 'data-type' is type of data represented by this structure in= stance: +if 'hierarchy' is 'memory', 'data-type' is 'access|read|write' latency or = 'access|read|write' +bandwidth of the target memory; if 'hierarchy' is 'first-level|second-leve= l|third-level', +'data-type' is 'access|read|write' hit latency or 'access|read|write' hit = bandwidth of the +target memory side cache. + +@var{lat} is latency value, the possible value and units are NUM[ns|us|ms] +(nanosecond|microsecond|millisecond), the recommended unit is 'ns'. @var{b= w} is +bandwidth value, the possible value and units are NUM[M|G|T], mean that the +bandwidth value are NUM byte (or MB/s, GB/s or TB/s depending on used suff= ix). +Note that if NUM is 0, means the corresponding latency or bandwidth inform= ation +is not provided. And if input numbers without any unit, the latency unit w= ill be +'ns' and the bandwidth will be B/s. + +For example, the following options describe 2 NUMA nodes. Node 0 has 2 cpu= s 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 Wed May 1 00:40:29 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=1574409470; cv=none; d=zoho.com; s=zohoarc; b=eIqAiukbvWMzVsEnoQ649ZHjXMMCXKR6vNnTTn+1BHnB3AKM4D9I/WlMGpkbH4eEEZH22enJ8aRUUBlGGM269DaNlBOQKrda29+J6VBjk+ng8HpOz9tdsCVkW+xX8ZwcacSjifptsTXhpX0IWGjgKFgxtKOCF2ME8bv4K+HmVcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409470; 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; bh=Q8fqEhcKc0Fn6vT7Av7ELylshjMVVUBq4TZnL+7JCGA=; b=hHW02wAK3RmJt1wtnnlPAwW7y59WoKx5qWn4oir9QoeZbpGx/X6+zoOxNONmvurp0Jgg9OAGKylWnUP8reXu53QkiCLJZiRUxrMB+GJhbU6whU8NJB6LXgDMeMg5uvrtdjB0YTuoSLqMUhTik+DCsM73R49hu3+wKUtW9BxhKPw= 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 1574409470480922.8255368789814; Thu, 21 Nov 2019 23:57:50 -0800 (PST) Received: from localhost ([::1]:48044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3p7-0007C3-6Y for importer@patchew.org; Fri, 22 Nov 2019 02:57:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39583) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gd-0005lw-Tb for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gb-0002t1-S0 for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:03 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gb-0002kF-Ea for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:01 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:49:01 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:48:57 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178551" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 09/14] numa: Extend CLI to provide memory side cache information Date: Fri, 22 Nov 2019 15:48:21 +0800 Message-Id: <20191122074826.1373-10-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 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 v17: - Use NumaHmatCacheOptions to replace HMAT_Cache_Info (Igor) - Add check for unordered cache level input (Igor) Changes in v16: - Add cross check with hmat_lb data (Igor) - Drop total_levels in struct HMAT_Cache_Info (Igor) - Correct the error table number (Igor) Changes in v15: - Change the QAPI version tag to 5.0 (Eric) --- hw/core/numa.c | 78 +++++++++++++++++++++++++++++++++++++++++++ include/sysemu/numa.h | 5 +++ qapi/machine.json | 78 +++++++++++++++++++++++++++++++++++++++++-- qemu-options.hx | 16 +++++++-- 4 files changed, 173 insertions(+), 4 deletions(-) diff --git a/hw/core/numa.c b/hw/core/numa.c index 70bc8a1081..7b1a9531d2 100644 --- a/hw/core/numa.c +++ b/hw/core/numa.c @@ -363,6 +363,71 @@ void parse_numa_hmat_lb(NumaState *numa_state, NumaHma= tLBOptions *node, g_array_append_val(hmat_lb->list, lb_data); } =20 +void parse_numa_hmat_cache(MachineState *ms, NumaHmatCacheOptions *node, + Error **errp) +{ + int nb_numa_nodes =3D ms->numa_state->num_nodes; + NodeInfo *numa_info =3D ms->numa_state->nodes; + NumaHmatCacheOptions *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 (numa_info[node->node_id].lb_info_provided !=3D (BIT(0) | BIT(1))) { + error_setg(errp, "The latency and bandwidth information of " + "node-id=3D%" PRIu32 " should be provided before memory= side " + "cache attributes", node->node_id); + return; + } + + if (node->level >=3D HMAT_LB_LEVELS) { + error_setg(errp, "Invalid level=3D%" PRIu8 ", it should be less th= an or " + "equal to %d", node->level, HMAT_LB_LEVELS - 1); + return; + } + assert(node->assoc < HMAT_CACHE_ASSOCIATIVITY__MAX); + assert(node->policy < HMAT_CACHE_WRITE_POLICY__MAX); + 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=3D%" PRIu64 ", the size of level=3D= %" PRIu8 + " should be small than the size(%" PRIu64 ") of " + "level=3D%" PRIu8, node->size, node->level, + ms->numa_state->hmat_cache[node->node_id] + [node->level - 1]->size, + node->level - 1); + return; + } + + if ((node->level < HMAT_LB_LEVELS - 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=3D%" PRIu64 ", the size of level=3D= %" PRIu8 + " should be larger than the size(%" PRIu64 ") 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)); + memcpy(hmat_cache, node, sizeof(*hmat_cache)); + 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; @@ -414,6 +479,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, enable it with -machine hmat= =3Don " + "before using any of hmat specific options"); + 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 70f93c83d7..ba693cc80b 100644 --- a/include/sysemu/numa.h +++ b/include/sysemu/numa.h @@ -91,6 +91,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 */ + NumaHmatCacheOptions *hmat_cache[MAX_NODES][HMAT_LB_LEVELS]; }; typedef struct NumaState NumaState; =20 @@ -98,6 +101,8 @@ void set_numa_options(MachineState *ms, NumaOptions *obj= ect, Error **errp); void parse_numa_opts(MachineState *ms); void parse_numa_hmat_lb(NumaState *numa_state, 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 67f5910400..999235bc1b 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -428,10 +428,12 @@ # # @hmat-lb: memory latency and bandwidth information (Since: 5.0) # +# @hmat-cache: memory side cache information (Since: 5.0) +# # 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: @@ -647,6 +650,77 @@ '*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-147 of ACPI 6.3 spec. +# +# @none: None +# +# @direct: Direct Mapped +# +# @complex: Complex Cache Indexing (implementation specific) +# +# Since: 5.0 +## +{ '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-147: Field "Cache Attributes" of ACPI 6.3 = spec. +# +# @none: None +# +# @write-back: Write Back (WB) +# +# @write-through: Write Through (WT) +# +# Since: 5.0 +## +{ '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-147: 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. +# +# @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: 5.0 +## +{ 'struct': 'NumaHmatCacheOptions', + 'data': { + 'node-id': 'uint32', + 'size': 'size', + 'level': 'uint8', + 'assoc': 'HmatCacheAssociativity', + 'policy': 'HmatCacheWritePolicy', + 'line': 'uint16' }} + ## # @HostMemPolicy: # diff --git a/qemu-options.hx b/qemu-options.hx index 929d275450..ad0e5aa190 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,level=3Dlevel[,assoc=3Dno= ne|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{hierarchy},data-type=3D@var{tpye}[,latency=3D@var{lat}][,bandwidth= =3D@var{bw}] +@itemx -numa hmat-cache,node-id=3D@var{node},size=3D@var{size},level=3D@va= r{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 @@ Note that if NUM is 0, means the corresponding latenc= y or bandwidth information is not provided. And if input numbers without any unit, the latency unit w= ill be 'ns' and the bandwidth will be B/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{level} is the c= ache +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 options describe 2 NUMA nodes. Node 0 has 2 cpu= s 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 10KB, 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=3D10K,level=3D1,assoc=3Ddirect,policy=3D= write-back,line=3D8 \ +-numa hmat-cache,node-id=3D1,size=3D10K,level=3D1,assoc=3Ddirect,policy=3D= write-back,line=3D8 @end example =20 ETEXI --=20 2.20.1 From nobody Wed May 1 00:40:29 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=1574409530; cv=none; d=zoho.com; s=zohoarc; b=XYz3+Isgqu6FbvjEiXKq9q8e+eBvuQb6ANRHB9+m2khIzAcgOLVPPPKX750LdKZGQ9I/0uwoXvauyfo3qg7iGWdtlIkbWBnr5gy41szZsdwZrBMS/LXamwF71edAzYAKPi8G+MRRcPYBfZkqujIkV1zv69g5+x8bbA+rOnbYXIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409530; 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; bh=5w57L7EQdlQpAqChNiPMNV4DpZaFbMvqHRr9bDC6Rz8=; b=BrnLEeSbPIjEKEjnsljWzwmyWZcrLYdlMptLAbs7IXH+CXjmPgcIO6Odsq/rQTKJW7NkdWUQYUnBfPu59gDzlyfsEscmcTCGnfjwnxdxdtyZot/oMGumQyfK8Ehiqxb1Uw1BNbLEEaE6YfPrUPptCGWEnhEZO+fckXOMrQGdkuA= 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 1574409530569328.0253093976884; Thu, 21 Nov 2019 23:58:50 -0800 (PST) Received: from localhost ([::1]:48060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3q4-0008S8-BP for importer@patchew.org; Fri, 22 Nov 2019 02:58:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39618) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gi-0005pq-PD for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gh-0002v4-1p for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:08 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gf-0002kF-7N for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:06 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:49:04 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:49:01 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178583" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 10/14] hmat acpi: Build Memory Proximity Domain Attributes Structure(s) Date: Fri, 22 Nov 2019 15:48:22 +0800 Message-Id: <20191122074826.1373-11-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 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: Igor Mammedov Reviewed-by: Daniel Black Reviewed-by: Jonathan Cameron Signed-off-by: Liu Jingqi Signed-off-by: Tao Xu --- No changes in v17. Changes in v16: - Use uint32_t for initiator and mem_node Changes in v13: - Remove the unnecessary head file. --- hw/acpi/Kconfig | 7 ++- hw/acpi/Makefile.objs | 1 + hw/acpi/hmat.c | 99 +++++++++++++++++++++++++++++++++++++++++++ hw/acpi/hmat.h | 42 ++++++++++++++++++ hw/i386/acpi-build.c | 5 +++ 5 files changed, 152 insertions(+), 2 deletions(-) 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 12e3f1e86e..54209c6f2f 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 @@ -23,6 +24,10 @@ config ACPI_NVDIMM bool depends on ACPI =20 +config ACPI_HMAT + bool + depends on ACPI + config ACPI_PCI bool depends on ACPI && PCI @@ -33,5 +38,3 @@ config ACPI_VMGENID depends on PC =20 config ACPI_HW_REDUCED - bool - depends on ACPI diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 655a9c1973..517bd88704 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -7,6 +7,7 @@ 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_HW_REDUCED) +=3D generic_event_device.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..9ff79308a4 --- /dev/null +++ b/hw/acpi/hmat.c @@ -0,0 +1,99 @@ +/* + * 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, + uint32_t initiator, uint32_t 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 *numa_s= tate) +{ + uint16_t flags; + int i; + + for (i =3D 0; i < numa_state->num_nodes; i++) { + flags =3D 0; + + if (numa_state->nodes[i].initiator < MAX_NODES) { + flags |=3D HMAT_PROXIMITY_INITIATOR_VALID; + } + + build_hmat_mpda(table_data, flags, numa_state->nodes[i].initiator,= i); + } +} + +void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *numa_st= ate) +{ + int hmat_start =3D table_data->len; + + /* reserve space for HMAT header */ + acpi_data_push(table_data, 40); + + hmat_build_table_structs(table_data, numa_state); + + 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..437dbc6872 --- /dev/null +++ b/hw/acpi/hmat.h @@ -0,0 +1,42 @@ +/* + * 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/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_PROXIMITY_INITIATOR_VALID 0x1 + +void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *numa_st= ate); + +#endif diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 12ff55fcfb..90a9c2ce6f 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -67,6 +67,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 @@ -2834,6 +2835,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 Wed May 1 00:40:29 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=1574409727; cv=none; d=zoho.com; s=zohoarc; b=CzmHErQlU4hu63KViyguJcCJlwBSkBgXSYMwVi/5EWdDjUChEHss1Ki12OIuXHVTniF+dTHP5CWlAPAMuSOtGNJISkjosgo8pHjGiPUM97sFWhcW5ZG5EJ0Hnmgf+imAOf5SeZf7RsT9fCVcPboFix6/oqGQiuZ/V2362vxdIZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409727; 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; bh=/MOY7lqu9WzUFId4ryKf3d8sApG3nHE60IBrXQJ/Uvc=; b=FSfdjpmchmJ4qmZ0ceqml5EgHxg/dAbYFkVHCRAPhjWzjZCPp9BgJgQ3yqdHJ0IXUGylb3h/5MW9dBzGLAqUMYN3tPP3UkzEKfTa6u33/jPmy1zbHJosxyMReND6lIkk/z5IIkmExd62DoatxO78jLknJzYu3FdcOL9lFbG1X5Y= 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 15744097271001003.0184045585258; Fri, 22 Nov 2019 00:02:07 -0800 (PST) Received: from localhost ([::1]:48108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3tF-0003WJ-4u for importer@patchew.org; Fri, 22 Nov 2019 03:02:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39632) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gk-0005qw-UZ for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gj-0002xF-19 for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:10 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gi-0002kF-PJ for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:08 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:49:07 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:49:05 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178599" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 11/14] hmat acpi: Build System Locality Latency and Bandwidth Information Structure(s) Date: Fri, 22 Nov 2019 15:48:23 +0800 Message-Id: <20191122074826.1373-12-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 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. Reviewed-by: Igor Mammedov Signed-off-by: Liu Jingqi Signed-off-by: Tao Xu --- Changes in v17: - Remove unnecessary header file (Igor) Changes in v16: - Add more description for lb_length (Igor) - Drop entry_list and calculate entries in this patch (Igor) Changes in v13: - Calculate the entries in a new patch. --- hw/acpi/hmat.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c index 9ff79308a4..e5ee8b4317 100644 --- a/hw/acpi/hmat.c +++ b/hw/acpi/hmat.c @@ -25,6 +25,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/units.h" #include "sysemu/numa.h" #include "hw/acpi/hmat.h" =20 @@ -67,11 +68,89 @@ static void build_hmat_mpda(GArray *table_data, uint16_= t flags, build_append_int_noprefix(table_data, 0, 8); } =20 +/* + * 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 i, index; + HMAT_LB_Data *lb_data; + uint16_t *entry_list; + uint32_t base; + /* Length in bytes for entire structure */ + uint32_t lb_length + =3D 32 /* Table length upto and including Entry Base Unit */ + + 4 * num_initiator /* Initiator Proximity Domain List */ + + 4 * num_target /* Target Proximity Domain List */ + + 2 * num_initiator * num_target; /* Latency or Bandwidth Entries = */ + + /* 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, lb_length, 4); + /* Flags: Bits [3:0] Memory Hierarchy, Bits[7:4] Reserved */ + assert(!(hmat_lb->hierarchy >> 4)); + build_append_int_noprefix(table_data, hmat_lb->hierarchy, 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, num_initiator, 4); + /* Number of Target Proximity Domains (t) */ + build_append_int_noprefix(table_data, num_target, 4); + /* Reserved */ + build_append_int_noprefix(table_data, 0, 4); + + /* Entry Base Unit */ + if (hmat_lb->data_type <=3D HMAT_LB_DATA_WRITE_LATENCY) { + /* Convert latency base from nanoseconds to picosecond */ + base =3D hmat_lb->base * 1000; + } else { + /* Convert bandwidth base from Byte to Megabyte */ + base =3D hmat_lb->base / MiB; + } + build_append_int_noprefix(table_data, base, 8); + + /* Initiator Proximity Domain List */ + for (i =3D 0; i < num_initiator; i++) { + build_append_int_noprefix(table_data, initiator_list[i], 4); + } + + /* Target Proximity Domain List */ + for (i =3D 0; i < num_target; i++) { + build_append_int_noprefix(table_data, i, 4); + } + + /* Latency or Bandwidth Entries */ + entry_list =3D g_malloc0(hmat_lb->list->len * sizeof(uint16_t)); + for (i =3D 0; i < hmat_lb->list->len; i++) { + lb_data =3D &g_array_index(hmat_lb->list, HMAT_LB_Data, i); + index =3D lb_data->initiator * num_target + lb_data->target; + + entry_list[index] =3D (uint16_t)(lb_data->data / hmat_lb->base); + } + + for (i =3D 0; i < num_initiator * num_target; i++) { + build_append_int_noprefix(table_data, entry_list[i], 2); + } + + g_free(entry_list); +} + /* Build HMAT sub table structures */ static void hmat_build_table_structs(GArray *table_data, NumaState *numa_s= tate) { uint16_t flags; - int i; + uint32_t num_initiator =3D 0; + uint32_t initiator_list[MAX_NODES]; + int i, hierarchy, type; + HMAT_LB_Info *hmat_lb; =20 for (i =3D 0; i < numa_state->num_nodes; i++) { flags =3D 0; @@ -82,6 +161,29 @@ static void hmat_build_table_structs(GArray *table_data= , NumaState *numa_state) =20 build_hmat_mpda(table_data, flags, numa_state->nodes[i].initiator,= i); } + + for (i =3D 0; i < numa_state->num_nodes; i++) { + if (numa_state->nodes[i].has_cpu) { + initiator_list[num_initiator++] =3D i; + } + } + + /* + * ACPI 6.3: 5.2.27.4 System Locality Latency and Bandwidth Information + * Structure: Table 5-146 + */ + for (hierarchy =3D HMAT_LB_MEM_MEMORY; + hierarchy <=3D HMAT_LB_MEM_CACHE_3RD_LEVEL; hierarchy++) { + for (type =3D HMAT_LB_DATA_ACCESS_LATENCY; + type <=3D HMAT_LB_DATA_WRITE_BANDWIDTH; type++) { + hmat_lb =3D numa_state->hmat_lb[hierarchy][type]; + + if (hmat_lb && hmat_lb->list->len) { + build_hmat_lb(table_data, hmat_lb, num_initiator, + numa_state->num_nodes, initiator_list); + } + } + } } =20 void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *numa_st= ate) --=20 2.20.1 From nobody Wed May 1 00:40:29 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=1574409760; cv=none; d=zoho.com; s=zohoarc; b=HaA2ahu7Tk9dkKw+8wQvaPPCiYdustWYnQe54mIKrIzDLENkHh9FhOatMicjMmnNuCIoIetxX6cXpveU2zcxgPjoC4BuutnS9EyXJ4UWje5U76zuLGua8RPpdg+ESD3fCORAPF6ENQfBYxKZGiagPPWjAPWYakU+pe9Qq7yRy+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409760; 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; bh=zec5VPG/8X3u2xZ7985NFiuKx0TckebCCeb6YZ3l9hU=; b=Yz00BSLP3lqEbIWdXk6wCw3oOKBUAmUu+HVRfpgEVa9kkgHDangAE9MB89qAgBaMteIxUMqO8s1ulEgKr8M4Doqg4Ndg94ICtbTrhV3WIyrHHPgBnS41FfdtxUhX2Wz8L4lLrKeEU4NGIEvDfrpJMyq3ToWoRJ+slEPOSMYeuP4= 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 1574409760084938.0286957239747; Fri, 22 Nov 2019 00:02:40 -0800 (PST) Received: from localhost ([::1]:48118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3tm-0004Fa-8H for importer@patchew.org; Fri, 22 Nov 2019 03:02:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39661) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gn-0005vS-9i for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gl-000300-St for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:13 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gl-0002kF-L3 for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:11 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:49:11 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:49:08 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178609" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 12/14] hmat acpi: Build Memory Side Cache Information Structure(s) Date: Fri, 22 Nov 2019 15:48:24 +0800 Message-Id: <20191122074826.1373-13-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 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 Reviewed-by: Igor Mammedov --- No changes in v17. Changes in v16: - Use checks and assert to replace masks (Igor) - Fields in Cache Attributes are promoted to uint32_t before shifting (Igor) - Drop cpu_to_le32() (Igor) Changes in v13: - rename level as cache_level --- hw/acpi/hmat.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c index e5ee8b4317..bb6adb0ccf 100644 --- a/hw/acpi/hmat.c +++ b/hw/acpi/hmat.c @@ -143,14 +143,62 @@ static void build_hmat_lb(GArray *table_data, HMAT_LB= _Info *hmat_lb, g_free(entry_list); } =20 +/* ACPI 6.3: 5.2.27.5 Memory Side Cache Information Structure: Table 5-147= */ +static void build_hmat_cache(GArray *table_data, uint8_t total_levels, + NumaHmatCacheOptions *hmat_cache) +{ + /* + * Cache Attributes: Bits [3:0] =E2=80=93 Total Cache Levels + * for this Memory Proximity Domain + */ + uint32_t cache_attr =3D total_levels; + + /* Bits [7:4] : Cache Level described in this structure */ + cache_attr |=3D (uint32_t) hmat_cache->level << 4; + + /* Bits [11:8] - Cache Associativity */ + cache_attr |=3D (uint32_t) hmat_cache->assoc << 8; + + /* Bits [15:12] - Write Policy */ + cache_attr |=3D (uint32_t) hmat_cache->policy << 12; + + /* Bits [31:16] - Cache Line size in bytes */ + cache_attr |=3D (uint32_t) hmat_cache->line << 16; + + /* 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->node_id, 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 *numa_s= tate) { uint16_t flags; uint32_t num_initiator =3D 0; uint32_t initiator_list[MAX_NODES]; - int i, hierarchy, type; + int i, hierarchy, type, cache_level, total_levels; HMAT_LB_Info *hmat_lb; + NumaHmatCacheOptions *hmat_cache; =20 for (i =3D 0; i < numa_state->num_nodes; i++) { flags =3D 0; @@ -184,6 +232,25 @@ static void hmat_build_table_structs(GArray *table_dat= a, NumaState *numa_state) } } } + + /* + * ACPI 6.3: 5.2.27.5 Memory Side Cache Information Structure: + * Table 5-147 + */ + for (i =3D 0; i < numa_state->num_nodes; i++) { + total_levels =3D 0; + for (cache_level =3D 1; cache_level < HMAT_LB_LEVELS; cache_level+= +) { + if (numa_state->hmat_cache[i][cache_level]) { + total_levels++; + } + } + for (cache_level =3D 0; cache_level <=3D total_levels; cache_level= ++) { + hmat_cache =3D numa_state->hmat_cache[i][cache_level]; + if (hmat_cache) { + build_hmat_cache(table_data, total_levels, hmat_cache); + } + } + } } =20 void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *numa_st= ate) --=20 2.20.1 From nobody Wed May 1 00:40:29 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=1574409919; cv=none; d=zoho.com; s=zohoarc; b=Z4F6t5XgW3cJPEs+BY0pfxMCJZyuJHHe+Xbk39gaZ684hpR/0ElJYKGjRjtP/2+juR/5yrllY/kieBqgPTJU0ysYHk0os3df1uor1bPdWgROyKzKphZMS6qES35ylaG3hMPa6Uy5hrb/G/aoXIphjl32f6UbgEty5YwkgUjBckU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574409919; 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; bh=KQoRVyuqg4Ee9crH3HYaxkKOQB4bvVGhKQedFMsfZPc=; b=UzjEP3KXQjqBjXZbMMFWh13uVLuWFEpJeS4VAqtigx3U+485dDrPS6GcE7RegV1ceytHLvZ6L4UDPKK4sGfz2JsHicdAcxNrIJS1xDsOmeyoZbZBxpKGfPttKZy5DwoBzJ8nwf6X0BV8Fue0tyEYPtzS7uon0FA77Qh+dyHA49c= 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 157440991924859.883191761428634; Fri, 22 Nov 2019 00:05:19 -0800 (PST) Received: from localhost ([::1]:48142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3wL-0007Zm-7T for importer@patchew.org; Fri, 22 Nov 2019 03:05:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39685) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gs-000631-LZ for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gp-00032J-MD for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:18 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gp-0002kF-9J for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:15 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:49:14 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:49:11 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178619" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 13/14] tests/numa: Add case for QMP build HMAT Date: Fri, 22 Nov 2019 15:48:25 +0800 Message-Id: <20191122074826.1373-14-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Check configuring HMAT usecase Suggested-by: Igor Mammedov Signed-off-by: Tao Xu Reviewed-by: Igor Mammedov --- Chenges in v17: - Add some fail test cases (Igor) --- tests/numa-test.c | 194 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) diff --git a/tests/numa-test.c b/tests/numa-test.c index 8de8581231..9c69da973c 100644 --- a/tests/numa-test.c +++ b/tests/numa-test.c @@ -327,6 +327,197 @@ static void pc_dynamic_cpu_cfg(const void *data) qtest_quit(qs); } =20 +static void pc_hmat_build_cfg(const void *data) +{ + QTestState *qs =3D qtest_initf("%s -nodefaults --preconfig -machine hm= at=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", + data ? (char *)data : ""); + + /* Fail: Initiator should be less than the number of nodes */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 2, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"access-latency\" } }"))); + + /* Fail: Target should be less than the number of nodes */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 2," + " 'hierarchy': \"memory\", 'data-type': \"access-latency\" } }"))); + + /* Fail: Initiator should contain cpu */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 1, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"access-latency\" } }"))); + + /* Fail: Data-type mismatch */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"write-latency\"," + " 'bandwidth': 524288000 } }"))); + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"read-bandwidth\"," + " 'latency': 5 } }"))); + + /* Fail: Bandwidth should be 1MB (1048576) aligned */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"access-bandwidth\"," + " 'bandwidth': 1048575 } }"))); + + /* Configuring HMAT bandwidth and latency details */ + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"access-latency\"," + " 'latency': 1 } }"))); /* 1 ns */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"access-latency\"," + " 'latency': 5 } }"))); /* Fail: Duplicate configuration */ + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"access-bandwidth\"," + " 'bandwidth': 68717379584 } }"))); /* 65534 MB/s */ + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 1," + " 'hierarchy': \"memory\", 'data-type': \"access-latency\"," + " 'latency': 65534 } }"))); /* 65534 ns */ + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 1," + " 'hierarchy': \"memory\", 'data-type': \"access-bandwidth\"," + " 'bandwidth': 34358689792 } }"))); /* 32767 MB/s */ + + /* Fail: node_id should be less than the number of nodes */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-cache', 'node-id': 2, 'size': 10240= ," + " 'level': 1, 'assoc': \"direct\", 'policy': \"write-back\"," + " 'line': 8 } }"))); + + /* Fail: level should be less than HMAT_LB_LEVELS (4) */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-cache', 'node-id': 0, 'size': 10240= ," + " 'level': 4, 'assoc': \"direct\", 'policy': \"write-back\"," + " 'line': 8 } }"))); + + /* Configuring HMAT memory side cache attributes */ + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-cache', 'node-id': 0, 'size': 10240= ," + " 'level': 1, 'assoc': \"direct\", 'policy': \"write-back\"," + " 'line': 8 } }"))); + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-cache', 'node-id': 0, 'size': 10240= ," + " 'level': 1, 'assoc': \"direct\", 'policy': \"write-back\"," + " 'line': 8 } }"))); /* Fail: Duplicate configuration */ + /* Fail: The size of level 2 size should be small than level 1 */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-cache', 'node-id': 0, 'size': 10240= ," + " 'level': 2, 'assoc': \"direct\", 'policy': \"write-back\"," + " 'line': 8 } }"))); + /* Fail: The size of level 0 size should be larger than level 1 */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-cache', 'node-id': 0, 'size': 10240= ," + " 'level': 0, 'assoc': \"direct\", 'policy': \"write-back\"," + " 'line': 8 } }"))); + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-cache', 'node-id': 1, 'size': 10240= ," + " 'level': 1, 'assoc': \"direct\", 'policy': \"write-back\"," + " 'line': 8 } }"))); + + /* let machine initialization to complete and run */ + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'x-exit-preconfig= ' }"))); + qtest_qmp_eventwait(qs, "RESUME"); + + qtest_quit(qs); +} + +static void pc_hmat_off_cfg(const void *data) +{ + QTestState *qs =3D qtest_initf("%s -nodefaults --preconfig " + "-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", + data ? (char *)data : ""); + + /* + * Fail: Enable HMAT with -machine hmat=3Don + * before using any of hmat specific options + */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'node', 'nodeid': 1, 'memdev': \"m1\"," + " 'initiator': 0 } }"))); + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'node', 'nodeid': 1, 'memdev': \"m1\" } }= "))); + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"access-latency\"," + " 'latency': 1 } }"))); + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-cache', 'node-id': 0, 'size': 10240= ," + " 'level': 1, 'assoc': \"direct\", 'policy': \"write-back\"," + " 'line': 8 } }"))); + + /* let machine initialization to complete and run */ + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'x-exit-preconfig= ' }"))); + qtest_qmp_eventwait(qs, "RESUME"); + + qtest_quit(qs); +} + +static void pc_hmat_erange_cfg(const void *data) +{ + QTestState *qs =3D qtest_initf("%s -nodefaults --preconfig -machine hm= at=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", + data ? (char *)data : ""); + + /* Can't store the compressed latency */ + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"access-latency\"," + " 'latency': 1 } }"))); /* 1 ns */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"access-latency\"," + " 'latency': 65535 } }"))); /* 65535 ns */ + + /* Test the 0 input (bandwidth not provided) */ + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 0," + " 'hierarchy': \"memory\", 'data-type': \"access-bandwidth\"," + " 'bandwidth': 0 } }"))); /* 0 MB/s */ + /* Fail: bandwidth should be provided before memory side cache attribu= tes */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-cache', 'node-id': 0, 'size': 10240= ," + " 'level': 1, 'assoc': \"direct\", 'policy': \"write-back\"," + " 'line': 8 } }"))); + + /* Can't store the compressed bandwidth */ + g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'set-numa-node'," + " 'arguments': { 'type': 'hmat-lb', 'initiator': 0, 'target': 1," + " 'hierarchy': \"memory\", 'data-type': \"access-bandwidth\"," + " 'bandwidth': 68718428160 } }"))); /* 65535 MB/s */ + + /* let machine initialization to complete and run */ + g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'x-exit-preconfig= ' }"))); + qtest_qmp_eventwait(qs, "RESUME"); + + qtest_quit(qs); +} + int main(int argc, char **argv) { const char *args =3D NULL; @@ -346,6 +537,9 @@ int main(int argc, char **argv) if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64")) { qtest_add_data_func("/numa/pc/cpu/explicit", args, pc_numa_cpu); qtest_add_data_func("/numa/pc/dynamic/cpu", args, pc_dynamic_cpu_c= fg); + qtest_add_data_func("/numa/pc/hmat/build", args, pc_hmat_build_cfg= ); + qtest_add_data_func("/numa/pc/hmat/off", args, pc_hmat_off_cfg); + qtest_add_data_func("/numa/pc/hmat/erange", args, pc_hmat_erange_c= fg); } =20 if (!strcmp(arch, "ppc64")) { --=20 2.20.1 From nobody Wed May 1 00:40:29 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=1574410076; cv=none; d=zoho.com; s=zohoarc; b=Yq0Um/g+5M6OcfeAtWAlNnPWA9oKkGtyGO3V66i7rjpuOspo5FEVMGSNL4ob6UyaqbJbJuDPMazVybWRAcxIRw3RFukOp5umBHQW0H/2PeR10JdawjJK3Phl56GpgQfOob0n9PuqUWx7BiwIbXch8voCwipoJVmq9Wg47c+3Tpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574410076; 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; bh=yQHwG8Ef8RPrSw2zXDDzX9MKZaNPdYpDZq+7UoJjKWE=; b=KVFkKsyD+8K98qGm6aZlz+IgB9dbQVcd2Dlgh8smfpQY4at1DTorNJ87/FR4PRLC/jzx9N5MWAHIgYSUUxf4lPdIldFADlmC6JUdbd9SsskuPTuMm0vnknWP2FDC1NmShAUmYDmpOlLeg2fdRq6r/TAo4YU/PjxK971ykq/C5Ac= 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 1574410076422756.9537623851699; Fri, 22 Nov 2019 00:07:56 -0800 (PST) Received: from localhost ([::1]:48194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3yt-0002iM-0B for importer@patchew.org; Fri, 22 Nov 2019 03:07:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39701) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iY3gu-00065K-0C for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iY3gs-00033A-JK for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:19 -0500 Received: from mga18.intel.com ([134.134.136.126]:36768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iY3gs-0002kF-BP for qemu-devel@nongnu.org; Fri, 22 Nov 2019 02:49:18 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 23:49:18 -0800 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by orsmga003.jf.intel.com with ESMTP; 21 Nov 2019 23:49:14 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,229,1571727600"; d="scan'208";a="210178630" From: Tao Xu To: mst@redhat.com, imammedo@redhat.com, eblake@redhat.com, ehabkost@redhat.com, marcel.apfelbaum@gmail.com, armbru@redhat.com, sw@weilnetz.de, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com Subject: [PATCH v17 14/14] tests/bios-tables-test: add test cases for ACPI HMAT Date: Fri, 22 Nov 2019 15:48:26 +0800 Message-Id: <20191122074826.1373-15-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122074826.1373-1-tao3.xu@intel.com> References: <20191122074826.1373-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: 134.134.136.126 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 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/data/acpi/pc/APIC.acpihmat tests/data/acpi/pc/SRAT.acpihmat tests/data/acpi/pc/HMAT.acpihmat tests/data/acpi/pc/DSDT.acpihmat tests/data/acpi/q35/APIC.acpihmat tests/data/acpi/q35/SRAT.acpihmat tests/data/acpi/q35/HMAT.acpihmat tests/data/acpi/q35/DSDT.acpihmat Reviewed-by: Igor Mammedov Reviewed-by: Daniel Black Reviewed-by: Jingqi Liu Suggested-by: Igor Mammedov Signed-off-by: Tao Xu --- Changes in v17: - Update the latency and bandwidth Changes in v15: - Make tests without breaking CI (Michael) Changes in v13: - Use decimal notation with appropriate suffix for cache size --- tests/bios-tables-test-allowed-diff.h | 8 +++++ tests/bios-tables-test.c | 44 +++++++++++++++++++++++++++ tests/data/acpi/pc/APIC.acpihmat | 0 tests/data/acpi/pc/DSDT.acpihmat | 0 tests/data/acpi/pc/HMAT.acpihmat | 0 tests/data/acpi/pc/SRAT.acpihmat | 0 tests/data/acpi/q35/APIC.acpihmat | 0 tests/data/acpi/q35/DSDT.acpihmat | 0 tests/data/acpi/q35/HMAT.acpihmat | 0 tests/data/acpi/q35/SRAT.acpihmat | 0 10 files changed, 52 insertions(+) create mode 100644 tests/data/acpi/pc/APIC.acpihmat create mode 100644 tests/data/acpi/pc/DSDT.acpihmat create mode 100644 tests/data/acpi/pc/HMAT.acpihmat create mode 100644 tests/data/acpi/pc/SRAT.acpihmat create mode 100644 tests/data/acpi/q35/APIC.acpihmat create mode 100644 tests/data/acpi/q35/DSDT.acpihmat create mode 100644 tests/data/acpi/q35/HMAT.acpihmat create mode 100644 tests/data/acpi/q35/SRAT.acpihmat diff --git a/tests/bios-tables-test-allowed-diff.h b/tests/bios-tables-test= -allowed-diff.h index dfb8523c8b..3c9e0c979b 100644 --- a/tests/bios-tables-test-allowed-diff.h +++ b/tests/bios-tables-test-allowed-diff.h @@ -1 +1,9 @@ /* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/pc/APIC.acpihmat", +"tests/data/acpi/pc/SRAT.acpihmat", +"tests/data/acpi/pc/HMAT.acpihmat", +"tests/data/acpi/pc/DSDT.acpihmat", +"tests/data/acpi/q35/APIC.acpihmat", +"tests/data/acpi/q35/SRAT.acpihmat", +"tests/data/acpi/q35/HMAT.acpihmat", +"tests/data/acpi/q35/DSDT.acpihmat", diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 79f5da092f..9fab1d0459 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -947,6 +947,48 @@ static void test_acpi_virt_tcg_numamem(void) =20 } =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=3D1ns" + " -numa hmat-lb,initiator=3D0,target=3D0,hierarchy=3Dmem= ory," + "data-type=3Daccess-bandwidth,bandwidth=3D65534M" + " -numa hmat-lb,initiator=3D0,target=3D1,hierarchy=3Dmem= ory," + "data-type=3Daccess-latency,latency=3D65534ns" + " -numa hmat-lb,initiator=3D0,target=3D1,hierarchy=3Dmem= ory," + "data-type=3Daccess-bandwidth,bandwidth=3D32767M" + " -numa hmat-cache,node-id=3D0,size=3D10K,level=3D1,asso= c=3Ddirect," + "policy=3Dwrite-back,line=3D8" + " -numa hmat-cache,node-id=3D1,size=3D10K,level=3D1,asso= c=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 { @@ -991,6 +1033,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); qtest_add_func("acpi/virt/numamem", test_acpi_virt_tcg_numamem); diff --git a/tests/data/acpi/pc/APIC.acpihmat b/tests/data/acpi/pc/APIC.acp= ihmat new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/data/acpi/pc/DSDT.acpihmat b/tests/data/acpi/pc/DSDT.acp= ihmat new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/data/acpi/pc/HMAT.acpihmat b/tests/data/acpi/pc/HMAT.acp= ihmat new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/data/acpi/pc/SRAT.acpihmat b/tests/data/acpi/pc/SRAT.acp= ihmat new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/data/acpi/q35/APIC.acpihmat b/tests/data/acpi/q35/APIC.a= cpihmat new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/data/acpi/q35/DSDT.acpihmat b/tests/data/acpi/q35/DSDT.a= cpihmat new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/data/acpi/q35/HMAT.acpihmat b/tests/data/acpi/q35/HMAT.a= cpihmat new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/data/acpi/q35/SRAT.acpihmat b/tests/data/acpi/q35/SRAT.a= cpihmat new file mode 100644 index 0000000000..e69de29bb2 --=20 2.20.1