From owner-svn-src-all@FreeBSD.ORG Thu Jun 23 16:57:05 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (unknown [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 390261065670; Thu, 23 Jun 2011 16:57:05 +0000 (UTC) (envelope-from mavbsd@gmail.com) Received: from mail-fx0-f54.google.com (mail-fx0-f54.google.com [209.85.161.54]) by mx1.freebsd.org (Postfix) with ESMTP id 63ADD8FC12; Thu, 23 Jun 2011 16:57:04 +0000 (UTC) Received: by fxm11 with SMTP id 11so2082315fxm.13 for ; Thu, 23 Jun 2011 09:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to :x-enigmail-version:content-type:content-transfer-encoding; bh=rx55yDT4P9+naxxIwJxoIEE70mjnuQlYeSCr6rnlCp8=; b=lODCAODRjDd9dOJbscfskZEUlPju9DCjRxU+EkFmQ6t9PPEtSj9lG9joiNV1AKdXFR B0Ae5be9KetoqE4I8DUOJMiq+N01pq3HSslAHSzAdTTHToHhKH5Es5JYeUG83ptFM2ur Nb1jLrKYtPCgOe+w8o9muRcE++k9khE9MFZqo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; b=BzmPn5ubwlsu5gTv8WegbDGyZeTszFPjsPEkorGeVElkMnstwB92TZKlGayLIK5UlU bRGsHBSrnx4ha5dSLmM6RRGAbLUJoB8mzzQ9MesZkB0EkzOVK0rirphpcRqEPk4IyVX9 TWIAfi5CJHRyLahfRju4Ku8SXbPZJc2XK3Ntk= Received: by 10.223.5.212 with SMTP id 20mr2969573faw.40.1308848223345; Thu, 23 Jun 2011 09:57:03 -0700 (PDT) Received: from mavbook2.mavhome.dp.ua (pc.mavhome.dp.ua [212.86.226.226]) by mx.google.com with ESMTPS id q14sm1104011faa.3.2011.06.23.09.57.00 (version=SSLv3 cipher=OTHER); Thu, 23 Jun 2011 09:57:01 -0700 (PDT) Sender: Alexander Motin Message-ID: <4E03701B.8090103@FreeBSD.org> Date: Thu, 23 Jun 2011 19:55:55 +0300 From: Alexander Motin User-Agent: Thunderbird 2.0.0.23 (X11/20091212) MIME-Version: 1.0 To: Marcel Moolenaar References: <201106221640.p5MGejHY057164@svn.freebsd.org> <4E021C8E.8010904@FreeBSD.org> <201106221455.07540.jkim@FreeBSD.org> <201106221924.50458.jkim@FreeBSD.org> <4E028921.2040805@FreeBSD.org> <8B9DCBA3-C3EC-43EE-8BEC-858A280A2096@xcllnt.net> <4E02989F.6040703@FreeBSD.org> <6D159261-7C57-4509-B41B-E440DBB4CBEA@xcllnt.net> In-Reply-To: <6D159261-7C57-4509-B41B-E440DBB4CBEA@xcllnt.net> X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r223426 - in head/sys: dev/acpica kern sys x86/x86 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2011 16:57:05 -0000 Marcel Moolenaar wrote: > On Jun 22, 2011, at 6:36 PM, Alexander Motin wrote: >> Marcel Moolenaar wrote: >>> On Jun 22, 2011, at 5:30 PM, Alexander Motin wrote: >>>> Marcel Moolenaar wrote: >>>>> On Jun 22, 2011, at 4:24 PM, Jung-uk Kim wrote: >>>>>> I just realized kern_clocksource.c was excluded for arm and ia64. >>>>>> Here is updated patch. Please ignore the previous one. >>>>> Any reason why we're not adding kern_clocksource.c for them? >>>> Their event timers code still waits for refactoring. I have neither >>>> documentation nor hardware for them. Help would be appreciated. >>> Can you give me a pointer to a document orpage that describes >>> what is being refactored, why and how? >> In short, timer management code was unified and formalized. Instead of >> direct programming periodic timers from MD code and calling hard-/ >> stat-/ profclock() from there, timer hardware should be exposed to the >> MI kernel using sys/timeet.h API to allow kern_clocksource.c manage it. >> Last require calling its cpu_initclocks_bsp() and cpu_initclocks_ap() >> callbacks from MD initialization code, and cpu_idleclock() and >> cpu_activeclock() from MD cpu_idle(). >> >> Here is some references: >> man 4 eventtimers >> http://wiki.freebsd.org/201010DevSummit?action=AttachFile&do=view&target=timers.pdf >> http://svnweb.freebsd.org/base?view=revision&revision=209371 >> http://svnweb.freebsd.org/base?view=revision&revision=212541 >> >> All architectures except ia64 and non-Marvell arm are already done, so >> you may took any of them as reference. Ask me if you have any questions. > > Can you give a quick outline of how all the various clock > related initializations and support code relate, interact > or even conflict? It's getting rather convoluted and want > to make sure I get the ordering and timing right. During probe, every event timer driver initializes hardware and calls et_register(). After probe done, on SI_SUB_CLOCKS SYSINIT stage MI cpu_initclocks_bsp() called from MD cpu_initclocks() chooses the best timer, chooses best hz, stathz and profhz values according to timer capabilities and starts timer. If timer is per-CPU, it starts only BSP one. Later, on SMP APs startup, when each CPU launched, cpu_initclocks_ap() is called to start per-CPU timers there. MI code no longer calls hard-/stat-/profclock(). Instead it calls registered callback function. Callback function expects to be called in hardware interrupt context: td_intr_nesting_level should be incremented and td_intr_frame should contain interrupt trapframe pointer. You may see lapic_handle_timer() in x86/x86/local_apic.c as workaround example, if needed. cpu_startprofclock() and cpu_stopprofclock() are MI now and should be removed from MD code. MI cpu_idleclock() and cpu_activeclock() should be called from MD cpu_idle() on per-CPU basis to reprogram timer when CPU enters/exits sleep state. They should be called within critical section to delay context switch on wakeup until all skipped during sleep time events are handled (by the cpu_activeclock()). Timer calls are serialized by caller by holding spin lock (per-CPU locks for per-CPU timers). Due to disabled interrupts, you are not allowed to sleep, wait for IPIs delivery or do anything else, that may cause deadlock with other CPUs. Depending on hardware implementation, you may need to take care to not loose events on short time intervals. It is especially important in one-shot mode, as timer won't be reloaded in that case. > Also: The ITC on ia64 is a per-CPU, one short and periodic > timer that has a fixed frequency. Though the architecture > does not guarantee that counters are synchronized, nor > that all CPUs in a system run at the same frequency which > means that the ITCs may not all run at the same frequency. > Does the et code work with that or do I need to impose a > restriction on what hardware configurations to support > and/or revert to having the ITC be a global timer and run > only on the BSP? Event timer API operates in terms of bintime time intervals. It doesn't depend on timer base frequency. kern_clocksource.c uses that frequency only to calculate more suitable hz/stathz/profhz values. It will survive wrong value there, or even zero, if frequency is unknown. If base frequency differs between CPUs, event timer driver should just properly handle requested bintime value, using proper base frequency when programming timer. In one-shot mode kern_clocksource.c doesn't depend on timer precision. In periodic mode it does, but some drift between CPUs is acceptable. -- Alexander Motin