NetBSD Problem Report #53186

From www@NetBSD.org  Mon Apr 16 03:22:51 2018
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 6C9BD7A111
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 16 Apr 2018 03:22:51 +0000 (UTC)
Message-Id: <20180416032250.245737A1BC@mollari.NetBSD.org>
Date: Mon, 16 Apr 2018 03:22:50 +0000 (UTC)
From: bruce.lilly@gmail.com
Reply-To: bruce.lilly@gmail.com
To: gnats-bugs@NetBSD.org
Subject: Portable run-time non-privileged determination of processor cache parameters
X-Send-Pr-Version: www-1.0

>Number:         53186
>Category:       kern
>Synopsis:       Portable run-time non-privileged determination of processor cache parameters
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 16 03:25:00 +0000 2018
>Originator:     Bruce Lilly
>Release:        6.1.5-7.1.2
>Organization:
none
>Environment:
N/A
>Description:
There appears to be no way for an unprivileged userland process to
determine CPU cache parameters (level, type, line size, associativity).

dmidecode attempts to provide that information, but 1) one cannot depend
on it being installed, 2) it requires superuser privilege to read
/dev/mem, and 3) it provides incorrect information in some cases.

sysctl apparently does not provide any relevant information; moreover
it is non-portable.

libcpuid can, with some effort, be built on NetBSD and can provide
the information for i386 and amd64 processors, providing limited
portability but requiring that external library.

Linux provides extensions to POSIX, X/OPEN sysconf() to return cache
information (see e.g. https://lists.onap.org/pipermail/lsb-bugs/2007-July/002268.html ).  It sure would be nice if NetBSD used the same
mechanism to make cache information available (actual values for
_SC_LEVEL1_DCACHE_SIZE etc. are unimportant).  I note that
/usr/include/sys/unistd.h has a section
/* Extensions found in Solaris and Linux. */
but unfortunately it doesn't have anything of interest.
>How-To-Repeat:

>Fix:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.