From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 22 10:59:05 2011 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 40DAF106566C for ; Wed, 22 Jun 2011 10:59:05 +0000 (UTC) (envelope-from onwahe@gmail.com) Received: from mail-pv0-f182.google.com (mail-pv0-f182.google.com [74.125.83.182]) by mx1.freebsd.org (Postfix) with ESMTP id 1B84E8FC0A for ; Wed, 22 Jun 2011 10:59:04 +0000 (UTC) Received: by pvg11 with SMTP id 11so578338pvg.13 for ; Wed, 22 Jun 2011 03:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=ntYXOhpMt7bdWgokyPHznyh1mi+Ja5WYoBbZpkehiKs=; b=XcYpsZkejax1mjLG1uilSyEoN2O5JQkJoWPWEwcJ2u9+Ld0eFDUA0fwuCpzwNhQEtV aYGbJmPNK3je+RAikQbkTJ3iEwlHWD8KZQivBD6woCTlsHP/agH05jHh/BTP3RexGPkr tIU1+kTXUZpaMvKEG0F2jbRcFMsXAiOP6WWTM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=W1n8mkJXN82oNyUcRVBgobmTtPbmOfV9ZJ/6i/GvdOXW7PjgXlZr8M4qQqvbHlYqT8 Ft1fPA67EmgUa+a9XJitor+RWbyqa0fqVIngWwh2oYF5vDyEGvrWjyk1L5LnnKTp8WVo 94DukvTxjSvEvsilGtWQZkT+HWc/aDb+8ltDo= MIME-Version: 1.0 Received: by 10.142.61.3 with SMTP id j3mr78081wfa.102.1308738835471; Wed, 22 Jun 2011 03:33:55 -0700 (PDT) Received: by 10.142.239.4 with HTTP; Wed, 22 Jun 2011 03:33:55 -0700 (PDT) Date: Wed, 22 Jun 2011 12:33:55 +0200 Message-ID: From: Svatopluk Kraus To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Subject: threads runtime value is incorrect (tc_cpu_ticks() problem) 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: Wed, 22 Jun 2011 10:59:05 -0000 Hi, I've tested FreeBSD-current from June 16 2011 on x86 (AMD Elan SC400). I found out that a sum of runtimes of all threads is about 120 minutes after 180 minutes of system uptime and the difference is getting worse with time. The problem is in tc_cpu_ticks() implementation which takes into acount just one timecounter overflow, but in tested BSP (16-bit hardware counter) very often more than one overflow occured between two tc_cpu_ticks() calls. I understand that 16-bit timecounter is a real relict nowadays, but I would like to solve the problem somehow reasonably. I have a few questions. According to description in definition of timecounter structure (sys/timetc.h), tc_get_timecount() should read the counter and tc_counter_mask should mask off any unimplemented bits. In tc_cpu_ticks(), if ticks count returned from tc_get_timecount() overflows then (tc_counter_mask + 1) is added to result. However, timecounter hardware can be initialized to value from interval (0, tc_counter_mask>, so if the description of tc_get_timecount() doesn't lie then adding (tc_counter_mask + 1) value at all times is not correct. Better description which satisfies tc_cpu_ticks() implementation is that tc_get_timecount() should count the ticks in interval <0, tc_counter_mask>. That's what i8254_get_timecount() (in sys/x86/isa/clock.c) does really. However, if tc_get_timecount() should count the ticks (and doesn't read the counter) then it can count the ticks in full uint64_t range? And tc_cpu_ticks() implementation could be very simple (not masking, not overflow checking). In i8254_get_timecount(), it is enough to change global variable 'i8254_offset' and local variable 'count' from uint16_t to uint64_t type. Now, cpu_ticks() (whichs point to tc_cpu_ticks() by default) is called from mi_switch() which must be called often enough to satisfy tc_cpu_ticks() implementation (recognize just one timecounter overflow). That limits some of system parameters (at least hz selection). It looks that tc_counter_mask is a little bit misused? Maybe, tc_cpu_ticks() is only used for back compatibility and new system should use set_cputicker() to change this default? Thanks for some help to better understand that. Svata