timing.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef TIMING_H
  17. #define TIMING_H
  18. /*
  19. * -- Initialiser la bibliothèque avec timing_init();
  20. * -- Mémoriser un timestamp :
  21. * tick_t t;
  22. * GET_TICK(t);
  23. * -- Calculer un intervalle en microsecondes :
  24. * TIMING_DELAY(t1, t2);
  25. */
  26. #include <sys/time.h>
  27. #include <unistd.h>
  28. #include <stdint.h>
  29. #include <common/config.h>
  30. #include <starpu.h>
  31. #ifdef USE_SYNC_CLOCK
  32. #include <time.h>
  33. #ifndef _POSIX_C_SOURCE
  34. /* for clock_gettime */
  35. #define _POSIX_C_SOURCE 199309L
  36. #endif
  37. /* we use the usual gettimeofday method */
  38. typedef struct tick_s
  39. {
  40. struct timespec ts;
  41. } tick_t;
  42. #define GET_TICK(t) clock_gettime(CLOCK_MONOTONIC, &((t).ts))
  43. #else // !USE_SYNC_CLOCK
  44. typedef union u_tick
  45. {
  46. uint64_t tick;
  47. struct
  48. {
  49. uint32_t low;
  50. uint32_t high;
  51. }
  52. sub;
  53. } tick_t;
  54. #if defined(__i386__) || defined(__pentium__) || defined(__pentiumpro__) || defined(__i586__) || defined(__i686__) || defined(__k6__) || defined(__k7__) || defined(__x86_64__)
  55. # define GET_TICK(t) __asm__ volatile("rdtsc" : "=a" ((t).sub.low), "=d" ((t).sub.high))
  56. #else
  57. //# error "Processeur non-supporté par timing.h"
  58. /* XXX */
  59. //#warning "unsupported processor GET_TICK returns 0"
  60. # define GET_TICK(t) do {} while(0);
  61. #endif
  62. #endif // USE_SYNC_CLOCK
  63. void __attribute__ ((unused)) timing_init(void);
  64. inline double __attribute__ ((unused)) tick2usec(long long t);
  65. inline double __attribute__ ((unused)) timing_delay(tick_t *t1, tick_t *t2);
  66. inline double __attribute__ ((unused)) timing_now(void);
  67. #endif /* TIMING_H */