From patchwork Wed Feb 14 14:31:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 85732 X-Patchwork-Delegate: palmer@dabbelt.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7664E385E02E for ; Wed, 14 Feb 2024 14:34:57 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 82A87385E006 for ; Wed, 14 Feb 2024 14:32:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 82A87385E006 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 82A87385E006 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::529 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707921182; cv=none; b=rYy5xQzEwza6h17KK1dTujYeBEDCtcjm2DLJvM8xMrknSDzDFyS/0Io6eYM01PqX6DR5j6y9+E0FTSrcaDBWVp1cCoaVEwLizET9L55mBbOEfFvGrh4H+PiqPrm9gME3788tcZcY7l7eyI8YEPyLldzK2g5pfI+IwHjuLLR/fRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707921182; c=relaxed/simple; bh=9HKwofNDtM3mQbdw5HQr4IwgKqiNwFrv7q8+/y8NToQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ghEzOX50hs+psByJahUe22BOL+R7zohr1qPGWEhUcRrfbeU81Ks5m733SfPIdxNM2T1LFXcUvKXfkH+p/urg/GxQq0a71N/zRsWcUfc0T1WkmXX/JuIbnh57NRYyp4zKdkuOVtu+fBtQJyZrsM8DdOaRJTlq4a1aFu5n224izFg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5d8ddbac4fbso4781568a12.0 for ; Wed, 14 Feb 2024 06:32:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1707921178; x=1708525978; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PmGUIHJh6VHAV6X1wPidNHCpvUG1fN4EMb5F0/4NlFc=; b=MeBWesYKaP+WlKDJ1GoZDmmMdv1xDy57UYh00sfs3HYCYkGq/7do1f0qHMQKbM6I6G 0+L1jr7F9D3m9mtUd34RwJXieKuJtzbmS9BUQXj3hmxt2qU9H97zD58/n5nmfmxr8hB9 fCX78ii83nlJrHwMKzFbr0pilsxqqWNhiwKZFCpW3ZRdUrB14RUh2wDkSd5UbEIjDV4T 9IUZJY0L9JTYj0loKDA+eEuBf8FqA1O8rXJa7bsniTCFUkI5NWKzxCeXsTblSougeKWy eVN5NZbdxX2npDsbbSm3GcuAqvOfqkZYDDVLVBxwxjilho+q+JfZ92IJvB3AxpSEvjgA aeGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707921178; x=1708525978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PmGUIHJh6VHAV6X1wPidNHCpvUG1fN4EMb5F0/4NlFc=; b=Ffvgxbjb9gp11iBiNX5kKnf1Zvoerw5Vy9TBh9MjR3b1IA13BDitiU/7W+hx67Hf2G GtfMHnEzw3LhPQ2rrEJh+I7UCRl9X8BhXMIfPoqfGNc44CkHV7DLFMPSJbjsjLflcxPu 7H3KJ5FEi3DG6PRVP2PAc2h5AekEm42R7InOeT3jcpKFmQrZ/DQh9iK11KE2Iui8ACt9 9btU1su9aLNCt2FZLrKVJOZiF00o2Qf4MMWBPKi6o060ZWinIAJShbwepFVSZ23cXcwK NEyOC8P9u3Wis5/DQXBgv+L1sOyua2eKopsNb/pUws+rJ57k8uS1+W5bTon7SIIUoVNt RsOQ== X-Gm-Message-State: AOJu0Yyn5wcagbakSCoXPLq9ku9Y1HXENn2LoParda3nRf4v5BhDobw6 tfdFDfnHa6MwhBRwHvrxF/aw56D69IqyDYMYAnXp4jTpeudH4wVy8Xi2zJyHkMCRQmgLpr3thrt P X-Google-Smtp-Source: AGHT+IHktMeO2BzPH7/ZPuTxVKQsGWN7To653ISkTJMioAGpyMcjmixM85oxU140VNvz+qAJfQDhgg== X-Received: by 2002:a17:90a:c585:b0:298:b784:c72a with SMTP id l5-20020a17090ac58500b00298b784c72amr2786823pjt.23.1707921178083; Wed, 14 Feb 2024 06:32:58 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWX+vMbYV+aiB+S1RiH1OJaujJ+qre7+Ma3dYil90Uk8LK1MvnQnaz8eQ4ZA3jzeScaolIHgAzZNWavTXN6cfWE21+4FuP1/ojq6gOo7XLCwE7SshP8Q53XJHS9Pits7QheiQFp8gAAINAlmc6hw8WsLtgPb20Bf1jAYAH/tdeU Received: from evan.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id k21-20020a635a55000000b005dc98d9114bsm1140255pgm.43.2024.02.14.06.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 06:32:57 -0800 (PST) From: Evan Green To: libc-alpha@sourceware.org Cc: vineetg@rivosinc.com, Florian Weimer , slewis@rivosinc.com, palmer@rivosinc.com, Evan Green Subject: [PATCH v12 6/7] riscv: Add ifunc helper method to hwprobe.h Date: Wed, 14 Feb 2024 06:31:57 -0800 Message-Id: <20240214143159.2951158-7-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240214143159.2951158-1-evan@rivosinc.com> References: <20240214143159.2951158-1-evan@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Add a little helper method so it's easier to fetch a single value from the hwprobe function when used within an ifunc selector. Signed-off-by: Evan Green --- (no changes since v11) Changes in v11: - Remove superfluous 'signed' (Adhemerval) - Put helper before __END_DECLS (Adhemerval) - Add comment about +1 on non-Linux systems (Stefan) Changes in v10: - Avoid implicit comparisons (Adhemerval) Changes in v9: - Use __inline rather than inline so c89 compiles (build-many-glibcs) Changes in v7: - Introduced static inline helper (Richard) sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h index 34a2e3dbc2..8ecb43bb69 100644 --- a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h +++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h @@ -22,6 +22,7 @@ #include #include +#include #ifdef __has_include # if __has_include () # include @@ -79,6 +80,34 @@ typedef int (*__riscv_hwprobe_t) (struct riscv_hwprobe *__pairs, size_t __pair_c __fortified_attr_access (__read_write__, 1, 2) __fortified_attr_access (__read_only__, 4, 3); +/* Helper function usable from ifunc selectors that probes a single key. */ +static __inline int +__riscv_hwprobe_one(__riscv_hwprobe_t hwprobe_func, + long long int key, + unsigned long long int *value) +{ + struct riscv_hwprobe pair; + int rc; + + /* Earlier versions of glibc pass NULL as the second ifunc parameter. Other C + libraries on non-Linux systems may pass +1 as this function pointer to + indicate no support. Users copying this function to exotic worlds + (non-Linux non-glibc) may want to do additional validity checks here. */ + if (hwprobe_func == NULL) + return ENOSYS; + + pair.key = key; + rc = hwprobe_func (&pair, 1, 0, NULL, 0); + if (rc != 0) + return rc; + + if (pair.key < 0) + return ENOENT; + + *value = pair.value; + return 0; +} + __END_DECLS #endif /* sys/hwprobe.h */