From patchwork Tue Feb 27 22:56:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 1905486 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=DR4vv+/W; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TktFy15nwz23d3 for ; Wed, 28 Feb 2024 09:59:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C6C43858D33 for ; Tue, 27 Feb 2024 22:59:00 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id BC3033858C35 for ; Tue, 27 Feb 2024 22:57:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC3033858C35 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 BC3033858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709074633; cv=none; b=Knw8rNMnt5faMrdvMDptCOYCNTj0IpzBMDcOz+ji+0lNiLS0YboqitopONmSVoviJBfcZT31NkcqUSXZ81w1fglWjVZ2m11veJF428y2ozSfoMzKzZx3YLgzbdJyjS+CBUWzWUNCwp/3swbuBxXXgZ7LJcpKVI9MnAVYSyF7eXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709074633; c=relaxed/simple; bh=9HKwofNDtM3mQbdw5HQr4IwgKqiNwFrv7q8+/y8NToQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Fue3S0VGESGNRcmJFRIkc0coaRFXcw+mq7jXvB4cD6W6KaNZnyKLISWzbYIK/dXnoF3iHdewtIPKEaYZ80EYc2sCzjghY2OIGti7Ivh8s/76ylZuiJ1aN63QZJBC2YbQWjNt9Lybj0DEuc3/o8xdPBKwol1e2w5kKtvCY/UyFOs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1dc9222b337so29819235ad.2 for ; Tue, 27 Feb 2024 14:57:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709074626; x=1709679426; 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=DR4vv+/W20monVKtcuBQT8xRKkj2XSiagKVhuYlwhQNZsSJcXVU9Opv5uQ6n3yufHD cjIdBPgkEbgt7JmDal2RrQsl5oT5v1k5pl7CdCDMxmozGKv/FrfqpuHf4G45RuM4mgPm awuMscDLENBL+dtaveW1Xkws7ijMiuuxj172U7Qplq83feNJjJSNWJowGupoP5yEsFfI cbMdzp4Jd/xN9o0hhVu1HPaHbP3y20jWUdNB7LySuWRLe8O6QaS8qXCvM7lcX7FENkQH qPj5o6Sf+gsQ5u+qMTSFkOXndJboRvnXRQ5GfwvdNSR+gNc+SJneenuHPKFEdsJGbeUF bSGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709074626; x=1709679426; 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=FHTmuua3W8USQqzl7OO/U/9VCCf1GnoLKITaLDeUH0kQouqyTM6rO7wGGnP3uCXAs4 8RKd6krkatsJ0l7Zp0P0doKrkSLh5E7/2PHYXqohxZET6mgPD4S3dbBEq+Josomooeg3 7Zp49KVlVEs/dWqcu5Xz8qiRnVEmFhZDj3Ot6H3/1nbah7upewXbiamWG+/GL+RvDHg3 DDlDpTWOm1s95io+xBDVAkxklpfpsv+oP94VpGwxc1XQqbXWGOEp9m+aOlYoIl/0h98B TqRSSYI69Xy+1nS68yeY54dWDkBei/a++edVp6xTCGrAPk6zNlilG2ZVa7zpeFkxaIJz uwvg== X-Gm-Message-State: AOJu0YwGZuabZpJ46sgU3bGSqpus2zHnQTvN8VTD14sAYZIhM4Guk1PJ lwv2hnnTtbXj2DHA5lopGpSTs36R7kMEqbfJLkbzrTk1czsJKcYz9yKLo185iU+Tu0vr7N+UKcU h X-Google-Smtp-Source: AGHT+IFT01LZA2Id3OaRZUgrKPCEh5n1xHVwY9T4yU9QWdF8mNEeAeppqNXvHsU5/EnE/nGQ8ePTnw== X-Received: by 2002:a17:903:1246:b0:1db:f830:c381 with SMTP id u6-20020a170903124600b001dbf830c381mr13821748plh.44.1709074625886; Tue, 27 Feb 2024 14:57:05 -0800 (PST) Received: from evan.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id li3-20020a170903294300b001dc90ac1cecsm2029225plb.284.2024.02.27.14.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:57:05 -0800 (PST) From: Evan Green To: libc-alpha@sourceware.org Cc: vineetg@rivosinc.com, slewis@rivosinc.com, Florian Weimer , palmer@rivosinc.com, Evan Green Subject: [PATCH v13 6/7] riscv: Add ifunc helper method to hwprobe.h Date: Tue, 27 Feb 2024 14:56:42 -0800 Message-Id: <20240227225644.724901-7-evan@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227225644.724901-1-evan@rivosinc.com> References: <20240227225644.724901-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+incoming=patchwork.ozlabs.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 */