From patchwork Wed Jan 10 20:51:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 83791 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 29FBF385801C for ; Wed, 10 Jan 2024 20:55:14 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id 4D3733861024 for ; Wed, 10 Jan 2024 20:52:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D3733861024 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 4D3733861024 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704919928; cv=none; b=YfZuo7lKvdUwRNJ4MnWTzC0UtN+ozkF8ID8s6gkSdlPs5tKMjFWPBH/Ja59RQrfhC0B0zA//sW8uRMjVmzITUlsjPpvHX2RzLObO46U8SrJNeciIc7DWZaJU9jrAp5ZR7LuWgvZC6PBPPMZ+3DJMHugkakjZwEwVbUlyqMrftf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704919928; c=relaxed/simple; bh=z6VXoFBA+32jBCa47aqApyIZUiDB2KrrUX8TgpuGbfY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=LZTR6EchC8QJFVCfZEHydPXxFQdgchc7qsJViTGxEqSzT01RodFB19tARzzLXR5ajSQRf1ZdIUQF3isdzq3zF2h4gCFNspchR8xUeWLa8kWeiP5i5wczNQ1viZO3s+ZeIQhC9kzelYO8RoMK5EDBSFsueznTnftJDsSm5Q/hWtY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-36066190a99so24120985ab.3 for ; Wed, 10 Jan 2024 12:52:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704919924; x=1705524724; 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=lt2XVN3bXGyFsWISuKinXHEQKwDeC3LYI5DtiHZ/o4E=; b=x/oQ+GyeHVxk6gu/ma7qkqGYwj+l7OfkKD1Zw2dImYgxicXsdMLEp1RafLtyaVTaVK FJPDkqRlCm13eW1S/BTuPlYCMH0JgoGj1beCypsi3iQSMzNaPXJE1i03XQYdS1y9HiZM 3ioeiom/RA4OIVSOEk2MATZ/Lhdj6HCPzYFwxMxglGcjqDtDEgn7JM7VmjftVLWXop1C c9MHh3lGRCMMxdNBYj/PnqQO1ckGyEN4xo5KV/i82dQ5OZP6Wu5gTlqouHMvcpxonV86 2BwLwFYGoRjCbFcq3tBKxdaTaahBMRSdkRq+X70E7qlGKbAq4CYPBFNXMffAt9M2oVn6 /wPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704919924; x=1705524724; 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=lt2XVN3bXGyFsWISuKinXHEQKwDeC3LYI5DtiHZ/o4E=; b=wWPbP6zInVEXPP7xiLP5Mne0960FYdzNn2uzmbv+KbNtfqI7JYHHpSGUljykFOtyU9 uCehTv4Ivl8LgIxqoeu/hNXa8LaXyIXxF8InGf03DAx5T+NsXmy+IdXuSV1y5JmdtBBW kN10TlVwjt69cWPtvrLJdwoUDw3ue7uISmvqgbGqYZK3B0YkAPeRchhIko+fvQaR6p4+ OxDAXd8Dd5MoFj2ujTnypNUKYH9jESlokP0fXOd43Wr0mt80Gu/6gPeiT1Lh6VPWoTLL 41z0J98n8wYxogPeNEJM4XRvVjpt83B88wRKNM/lyoK64zzsYMDfWiyVYHDWYkqQDf+q z8jQ== X-Gm-Message-State: AOJu0YysEpDH2xmCwd1DZ7x5SuR6bDh4M53bLW/K8zcGI1snhnZ751zb GthCn7izI9smbNqWCKTRVvmRXvAJdxFXsy005r3Al7Yy3nI= X-Google-Smtp-Source: AGHT+IGfdItD12QziXLFtf/Efgnx2FJA3bbo+xw9VYOQRSNuEq6e3oW5rwtFy/v3HN9zhMqVi3RmuA== X-Received: by 2002:a05:6e02:156a:b0:360:197:55d1 with SMTP id k10-20020a056e02156a00b00360019755d1mr148401ilu.23.1704919924674; Wed, 10 Jan 2024 12:52:04 -0800 (PST) Received: from evan.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id y4-20020a92c984000000b0035ff9825323sm1452018iln.30.2024.01.10.12.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 12:52:04 -0800 (PST) From: Evan Green To: libc-alpha@sourceware.org Cc: palmer@rivosinc.com, vineetg@rivosinc.com, slewis@rivosinc.com, Florian Weimer , Evan Green Subject: [PATCH v11 6/7] riscv: Add ifunc helper method to hwprobe.h Date: Wed, 10 Jan 2024 12:51:39 -0800 Message-Id: <20240110205140.754849-7-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240110205140.754849-1-evan@rivosinc.com> References: <20240110205140.754849-1-evan@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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 --- 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 */