From owner-cvs-src Mon Mar 10 10: 4:21 2003 Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 33D0137B401; Mon, 10 Mar 2003 10:04:19 -0800 (PST) Received: from critter.freebsd.dk (critter.freebsd.dk [212.242.86.163]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4567343FA3; Mon, 10 Mar 2003 10:04:18 -0800 (PST) (envelope-from phk@phk.freebsd.dk) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.12.8/8.12.8) with ESMTP id h2AI47uP002857; Mon, 10 Mar 2003 19:04:16 +0100 (CET) (envelope-from phk@phk.freebsd.dk) To: Nate Lawson Cc: cvs-src@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: cvs commit: src/sys/sys devicestat.h From: "Poul-Henning Kamp" In-Reply-To: Your message of "Mon, 10 Mar 2003 09:33:13 PST." Date: Mon, 10 Mar 2003 19:04:07 +0100 Message-ID: <2856.1047319447@critter.freebsd.dk> Sender: owner-cvs-src@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message , Nate Lawson wri tes: >On Sun, 9 Mar 2003, Poul-Henning Kamp wrote: >> In message , Nate Lawson wri >> tes: >> >> >> Yes, these structures will be mmap'ed from kernel to userland and user >> >> land will (likely) memcpy() them to private storage as snapshot'ing. >> >> To be able to tell if you have an atomic snapshot, the two counters >> >> must be identical. >> > >> >How about a mtx covering the structure and a read from the device returns >> >the structure under lock? >> >> The goal is to avoid locking in the kernel and put the overhead in >> userland. Remember, most of the time nobody cares about the statistics >> so they should be cheap. > >I'm unsure why two counters are required. One counter at the start of the >structure is sufficient if you 1. memcpy the structure and then 2. re-read >the counter int to make sure it is the same as the one covered by the >memcpy. (This assumes memcpy can read an int atomically which should be >true). Hmm, a volatile keyword may be necessary for the user-visible >struct. Think two cpu system. One cpu doing the memcpy in userland while the other is updating the data structure in the kernel. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-src" in the body of the message