[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] libs/light: use the cpuid feature names from cpufeatureset.h


  • To: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 7 Jun 2023 11:05:17 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E+3oVSBcD7IM0Z3l0dlg0CNigJthDWljpZG+kthmr/0=; b=ko6dmPojmlqKgpXYlVPhidTi6wKeYSCI1AXPmJ59uEkVU92WxorRfp46J+nW+//CU57MyPgWvY3MppJf3ohQW2FAcHHsochcGBrBHr5Gb6UcMNdQDGJKmYvoWehOi4QECEpzybanNpLP2du7dMkL+kFIJsEQ9cnu1PSl1hYfBmhN8FU0qiwLK5h5xPf9MYqdh9bope2ox0nzOPZu4rZSMdGHUVq4voAQv40HvCSwMJ5ekmk4ngbDMEa9Q/0QvZgQxWKx3aCyIw2zk5b4dKtWaCGrzsWz1G05jFGCNWhOHKyT8v+VeguMqnQ3ftjez9gwJlSndVYlbrmqmFJ6nCOYwA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j61z2be28LWX0FYoqOTdoh++6WvL3zZvqtDJplHtvmtkpFuhPmUNkg9F1JZRS42+DuTOjM63hIYkfx/Nv8LDuWtG9zDL58MwvimT4tOOwhIDqJTsbv/8RPryQQiolwkqX77O8+eCrh/0TWofNBz/0VUFcVFFlR8FzpeJjIjryT7se1cVxwFVHlIZON37ZsG/Ckm2Mv8h43xH1pRTY7gLbtNeqAvvl6EcIdRJpmPiPkKjJD/1KlAINKum34zd4KlC8wUh7hiOmiPMFqyf+9MMNx3hHnWgSdsqabXSt+i9cW3iA78YgE7s2pvogj0NVPdCwYxf6BdTeCsF9BI7lt9kRA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: andrew.cooper3@xxxxxxxxxx, Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 07 Jun 2023 09:06:01 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 05.06.2023 12:36, Roger Pau Monne wrote:
> @@ -51,7 +53,7 @@ void libxl_cpuid_dispose(libxl_cpuid_policy_list 
> *p_cpuid_list)
>   * Used for the static structure describing all features.
>   */
>  struct cpuid_flags {
> -    char* name;
> +    const char* name;

Nit: Would you mind also moving * to its designated position at this
occasion?

> @@ -81,6 +83,14 @@ static libxl_cpuid_policy_list 
> cpuid_find_match(libxl_cpuid_policy_list *list,
>      return *list + i;
>  }
>  
> +static int search_feature(const void *a, const void *b)
> +{
> +    const char *key = a;
> +    const char *feat = ((struct { const char *n; } *)b)->n;

Urgh - what a cast. There's no connection at all between this and
struct feature_name in libxl_cpuid_parse_config(). I think you want
to move that type declaration out of the function, to also use it
here. But if not, comments on both sides are going to be necessary
imo.

> +    return strncmp(key, feat, strlen(key)) ?: strlen(key) - strlen(feat);

Why not simply

    return strcmp(key, feat);

? Both names are nul-terminated, first and foremost because
otherwise using strlen() wouldn't be appropriate either.

> @@ -342,6 +214,28 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list 
> *cpuid, const char* str)
>          if(!strncmp(str, flag->name, sep - str) && flag->name[sep - str] == 
> 0)
>              break;
>      }
> +    if (flag->name == NULL) {
> +        const struct feature_name *feat;
> +        /* Provide a NUL terminated feature name to the search helper. */
> +        char *name = strndup(str, sep - str);
> +
> +        if (name == NULL)
> +            return 4;
> +
> +        feat = bsearch(name, features, ARRAY_SIZE(features), 
> sizeof(features[0]),
> +                       search_feature);
> +        free(name);
> +
> +        if (feat != NULL) {
> +                f.name = feat->name;
> +                f.leaf = feature_to_cpuid[feat->bit / 32].leaf;
> +                f.subleaf = feature_to_cpuid[feat->bit / 32].subleaf;
> +                f.reg = feature_to_cpuid[feat->bit / 32].reg;
> +                f.bit = feat->bit % 32;
> +                f.length = 1,
> +                flag = &f;

Nit: Too deep indentation throughout here.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.