From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D9F48BB83 for ; Wed, 24 May 2006 17:53:05 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k4OFr5ZA003205 for ; Wed, 24 May 2006 17:53:05 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA26516 for ; Wed, 24 May 2006 17:53:04 +0200 (MET DST) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k4OFr3lo003193 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 24 May 2006 17:53:04 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Fivf4-0007gO-Lv for caml-list@inria.fr; Wed, 24 May 2006 17:52:38 +0200 Received: from 209.213.205.130 ([209.213.205.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 May 2006 17:52:38 +0200 Received: from sds by 209.213.205.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 May 2006 17:52:38 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: caml-list@inria.fr To: caml-list@inria.fr From: Sam Steingold Subject: pthread_getcpuclockid et al Date: Wed, 24 May 2006 11:51:46 -0400 Organization: disorganization Message-ID: Reply-To: sds@podval.org Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 209.213.205.130 Mail-Copies-To: never X-Attribution: Sam X-Disclaimer: You should not expect anyone to agree with me. User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:sIA+EXrkfTLsh9XP68hXXzcci3M= Sender: news X-Miltered: at concorde with ID 44748161.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4474815F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 otherlibs:01 systhreads:01 posix:01 struct:01 mli:01 mli:01 mlvalues:01 alloc:01 usr:01 lib:01 tar:01 otherlibs:01 systhreads:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.6 required=5.0 tests=RCVD_BY_IP,RCVD_NUMERIC_HELO autolearn=disabled version=3.0.3 How do I time an individual Ocaml thread? There appears to be no interface to pthread_getcpuclockid() and clock_gettime() and it is not obvious from ocaml/otherlibs/systhreads/posix.c how to get the pthread_t of a given Ocaml Thread.t object (caml_thread_descr does not point to a caml_thread_struct). here is what I have so far: =========================== pth_clock.mli type clock external getcpuclock: Thread.t -> clock = "getcpuclock" =========================== pth_clock.mli =========================== pth_clock.ml external getcpuclock : Thread.t -> clock = "getcpuclock" =========================== pth_clock.ml =========================== pth_clock.c #include #include #include #include #include #include #include /* see /usr/local/home/godi/godi/lib/godi/saved-src/ocaml.tar.gz ocaml/otherlibs/systhreads/posix.c */ extern pthread_t tid_to_pth (value tid);/* how do I define this??? */ /* Encapsulation of clockid_t as Caml custom blocks. */ #define clock_val(v) (*((clockid_t **) Data_custom_val(v))) void clock_finalize (value v) { free(clock_val(v)); } static struct custom_operations clockid_ops = { "caml.clockid_t", &clock_finalize, custom_compare_default, custom_hash_default, custom_serialize_default, custom_deserialize_default }; /* Allocating a Caml custom block to hold the given clockid_t * */ static value alloc_clock (clockid_t * c) { value v = alloc_custom(&clockid_ops, sizeof(clockid_t *), 0, 1); clock_val(v) = c; return v; } CAMLprim value getcpuclock (value tid) { CAMLparam1(tid); clockid_t *c = malloc(sizeof(clockid_t)); if (pthread_getcpuclockid(tid_to_pth(tid),c) == 0) CAMLreturn(alloc_clock(c)); else { free(c); caml_failwith("pthread_getcpuclockid"); } } =========================== pth_clock.c Help? Thanks. -- Sam Steingold (http://www.podval.org/~sds) on Fedora Core release 5 (Bordeaux) http://pmw.org.il http://openvotingconsortium.org http://dhimmi.com http://thereligionofpeace.com http://palestinefacts.org http://ffii.org Why do we want intelligent terminals when there are so many stupid users?