From owner-freebsd-hackers@FreeBSD.ORG Sun May 18 18:06:26 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3C1331065679 for ; Sun, 18 May 2008 18:06:26 +0000 (UTC) (envelope-from mwm-keyword-freebsdhackers2.e313df@mired.org) Received: from mired.org (five.mired.org [66.92.153.75]) by mx1.freebsd.org (Postfix) with ESMTP id D69C68FC15 for ; Sun, 18 May 2008 18:06:25 +0000 (UTC) (envelope-from mwm-keyword-freebsdhackers2.e313df@mired.org) Received: (qmail 75378 invoked by uid 1001); 18 May 2008 14:06:52 -0400 Received: from bhuda.mired.org (bhuda [192.168.195.1]) by bhuda (tmda-ofmipd) with ESMTP; Sun, 18 May 2008 14:06:51 -0400 Date: Sun, 18 May 2008 14:06:50 -0400 To: Rui Paulo Message-ID: <20080518140650.2691af1c@bhuda.mired.org> In-Reply-To: <48305044.7000007@FreeBSD.org> References: <482E93C0.4070802@icyb.net.ua> <20080517133037.3a3935db@bhuda.mired.org> <48305044.7000007@FreeBSD.org> Organization: Meyer Consulting X-Mailer: Claws Mail 3.4.0 (GTK+ 2.12.9; amd64-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: Mike Meyer Cc: freebsd-hackers@freebsd.org, Mike Meyer Subject: Re: rdmsr from userspace X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 May 2008 18:06:26 -0000 On Sun, 18 May 2008 16:50:28 +0100 Rui Paulo wrote: > Mike Meyer wrote: > > On Sat, 17 May 2008 11:13:52 +0300 > > Andriy Gapon wrote: > >> It seems that rdmsr instruction can be executed only at the highest > >> privilege level and thus is not permitted from userland. Maybe we should > >> provide something like Linux /dev/cpu/msr? > >> I don't like interface of that device, I think that ioctl approach would > >> be preferable in this case. > >> Something like create /dev/cpuN and allow some ioctls on it: > >> ioctl(cpu_fd, CPU_RDMSR, arg). > >> What do you think? > > > > Ok, this points directly at a question I've been wondering about, but > > haven't been able to find an answer in the google. > > > > I've been mucking about with general access to sysctl's (a sysctl > > plugin for gkrellm, and a python module for accessing sysctls), and > > with that hammer in my hand, the nail for this problem is obviously a > > dev.cpu.#.msr sysctl. > > How can you request a rdmsr within the sysctl tree? I don't think sysctl > is appropriate here either. Reading (or writing) a sysctl mib can trigger a sysctl handler, which can do pretty much anything. In particular, there are already examples in the kernel where sysctl handlers use devices that don't have /dev entries to get & set their values. Look through kern/kern_cpu.c and i386/cpufreq/p4tcc.c to see the two ends of that kind of connection. In fact, the cpu frequency sysctls would seem to be an excellent model for something like the msr. ioctl, open+read/write, sysctl - they're all just interfaces to kernel handlers. http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org