gvltools 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42d6e3f8ea2cc420e17a413a62fba51ccb6c2b90dac11138186e9f4d203bed51
4
- data.tar.gz: 97576f44774bb991699152d36140714b792e17ced8a7ea48d1210f0c8d94b1df
3
+ metadata.gz: ed2a6e0154120c8b048e3b92db8e6f6c4a87d2b653b105b90a06a171ca61895b
4
+ data.tar.gz: a976aab0ebf0da04af47d53587c144b7e89eeeef8f078c5b115d037db0fe3f6b
5
5
  SHA512:
6
- metadata.gz: ae23c00ab1f94c2af17753f5ba847690ebea31cb0d3f23134080ad34a475686ac0d9872fa56025a1fab8135c5ee57c58e19675bbc08160c9444a8d30edb847db
7
- data.tar.gz: 54e1694fd5d16935c98a6b838fdf188427cf645f0fe00ac08a7323609c70f01721d9836b80c6bdf2096ee7341d4d39a44f713b20a770470072c72c48887564c3
6
+ metadata.gz: baca86f153a68a90ca36213775bd22d5263325e98fdf3cd3332c4b3db953014c7c9a8e14c9ddee27ad0b19de5300065fd77d79d795d7ad8f931d45838f797921
7
+ data.tar.gz: be738a183964c4b6e0ef4f9ff5b9aac5e1a9b983d3fffe38034a338416260dc8be5fd95fcc23fe35697c2cc9d79ab8b1e8689deb3907e07468fe8e9985247911
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2023-03-28
4
+
5
+ - Use C11 atomics instead of MRI's `rb_atomic_t`.
6
+
3
7
  ## [0.1.0] - 2022-06-14
4
8
 
5
9
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gvltools (0.1.0)
4
+ gvltools (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -32,6 +32,7 @@ GEM
32
32
  unicode-display_width (2.1.0)
33
33
 
34
34
  PLATFORMS
35
+ aarch64-linux
35
36
  arm64-darwin-21
36
37
  arm64-darwin-22
37
38
  x86_64-linux
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "mkmf"
4
- if RUBY_ENGINE == "ruby" && have_func("rb_internal_thread_add_event_hook", ["ruby/thread.h"])
4
+ if RUBY_ENGINE == "ruby" &&
5
+ have_header("stdatomic.h") &&
6
+ have_func("rb_internal_thread_add_event_hook", ["ruby/thread.h"])
7
+
5
8
  $CFLAGS << " -O3 -Wall "
6
9
  create_makefile("gvltools/instrumentation")
7
10
  else
@@ -1,7 +1,9 @@
1
1
  #include <time.h>
2
2
  #include <ruby.h>
3
3
  #include <ruby/thread.h>
4
- #include <ruby/atomic.h>
4
+ #include <stdatomic.h>
5
+
6
+ typedef unsigned long long counter_t;
5
7
 
6
8
  // Metrics
7
9
  static rb_internal_thread_event_hook_t *gt_hook = NULL;
@@ -31,8 +33,8 @@ static inline void gt_gettime(struct timespec *time) {
31
33
  }
32
34
  }
33
35
 
34
- static inline rb_atomic_t gt_time_diff_ns(struct timespec before, struct timespec after) {
35
- rb_atomic_t total = 0;
36
+ static inline counter_t gt_time_diff_ns(struct timespec before, struct timespec after) {
37
+ counter_t total = 0;
36
38
  total += (after.tv_nsec - before.tv_nsec);
37
39
  total += (after.tv_sec - before.tv_sec) * SECONDS_TO_NANOSECONDS;
38
40
  return total;
@@ -67,16 +69,16 @@ static VALUE gt_disable_metric(VALUE module, VALUE metric) {
67
69
  }
68
70
 
69
71
  // GVLTools::LocalTimer and GVLTools::GlobalTimer
70
- static rb_atomic_t global_timer_total = 0;
71
- static THREAD_LOCAL_SPECIFIER uint64_t local_timer_total = 0;
72
+ static _Atomic counter_t global_timer_total = 0;
73
+ static THREAD_LOCAL_SPECIFIER counter_t local_timer_total = 0;
72
74
  static THREAD_LOCAL_SPECIFIER struct timespec timer_ready_at = {0};
73
75
 
74
76
  static VALUE global_timer_monotonic_time(VALUE module) {
75
- return UINT2NUM(global_timer_total);
77
+ return ULL2NUM(global_timer_total);
76
78
  }
77
79
 
78
80
  static VALUE global_timer_reset(VALUE module) {
79
- RUBY_ATOMIC_SET(global_timer_total, 0);
81
+ global_timer_total = 0;
80
82
  return Qtrue;
81
83
  }
82
84
 
@@ -90,14 +92,14 @@ static VALUE local_timer_reset(VALUE module) {
90
92
  }
91
93
 
92
94
  // Thread counts
93
- static rb_atomic_t waiting_threads_total = 0;
95
+ static _Atomic counter_t waiting_threads_total = 0;
94
96
 
95
97
  static VALUE waiting_threads_count(VALUE module) {
96
- return UINT2NUM(waiting_threads_total);
98
+ return ULL2NUM(waiting_threads_total);
97
99
  }
98
100
 
99
101
  static VALUE waiting_threads_reset(VALUE module) {
100
- RUBY_ATOMIC_SET(waiting_threads_total, 0);
102
+ waiting_threads_total = 0;
101
103
  return Qtrue;
102
104
  }
103
105
 
@@ -120,7 +122,7 @@ static void gt_thread_callback(rb_event_flag_t event, const rb_internal_thread_e
120
122
  if (!was_ready) was_ready = true;
121
123
 
122
124
  if (ENABLED(WAITING_THREADS)) {
123
- RUBY_ATOMIC_INC(waiting_threads_total);
125
+ waiting_threads_total++;
124
126
  }
125
127
 
126
128
  if (ENABLED(TIMER_GLOBAL | TIMER_LOCAL)) {
@@ -132,20 +134,20 @@ static void gt_thread_callback(rb_event_flag_t event, const rb_internal_thread_e
132
134
  if (!was_ready) break; // In case we registered the hook while some threads were already waiting on the GVL
133
135
 
134
136
  if (ENABLED(WAITING_THREADS)) {
135
- RUBY_ATOMIC_DEC(waiting_threads_total);
137
+ waiting_threads_total--;
136
138
  }
137
139
 
138
140
  if (ENABLED(TIMER_GLOBAL | TIMER_LOCAL)) {
139
141
  struct timespec current_time;
140
142
  gt_gettime(&current_time);
141
- rb_atomic_t diff = gt_time_diff_ns(timer_ready_at, current_time);
143
+ counter_t diff = gt_time_diff_ns(timer_ready_at, current_time);
142
144
 
143
145
  if (ENABLED(TIMER_LOCAL)) {
144
146
  local_timer_total += diff;
145
147
  }
146
148
 
147
149
  if (ENABLED(TIMER_GLOBAL)) {
148
- RUBY_ATOMIC_ADD(global_timer_total, diff);
150
+ global_timer_total += diff;
149
151
  }
150
152
  }
151
153
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GVLTools
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gvltools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-17 00:00:00.000000000 Z
11
+ date: 2023-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.4.1
70
+ rubygems_version: 3.4.6
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: Set of GVL instrumentation tools