uringmachine 0.19.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -1
  3. data/TODO.md +0 -1
  4. data/examples/bm_fileno.rb +33 -0
  5. data/examples/bm_mutex.rb +85 -0
  6. data/examples/bm_mutex_single.rb +33 -0
  7. data/examples/bm_queue.rb +27 -28
  8. data/examples/bm_send.rb +2 -5
  9. data/examples/bm_snooze.rb +20 -42
  10. data/examples/fiber_scheduler_demo.rb +15 -51
  11. data/examples/fiber_scheduler_fork.rb +24 -0
  12. data/examples/nc_ssl.rb +71 -0
  13. data/ext/um/extconf.rb +5 -15
  14. data/ext/um/um.c +57 -41
  15. data/ext/um/um.h +21 -11
  16. data/ext/um/um_async_op_class.c +2 -2
  17. data/ext/um/um_buffer.c +1 -1
  18. data/ext/um/um_class.c +94 -23
  19. data/ext/um/um_const.c +51 -3
  20. data/ext/um/um_mutex_class.c +1 -1
  21. data/ext/um/um_queue_class.c +1 -1
  22. data/ext/um/um_stream.c +5 -5
  23. data/ext/um/um_stream_class.c +3 -0
  24. data/ext/um/um_sync.c +22 -27
  25. data/ext/um/um_utils.c +59 -19
  26. data/grant-2025/journal.md +229 -0
  27. data/grant-2025/tasks.md +66 -0
  28. data/lib/uringmachine/fiber_scheduler.rb +180 -48
  29. data/lib/uringmachine/version.rb +1 -1
  30. data/lib/uringmachine.rb +6 -0
  31. data/test/test_fiber_scheduler.rb +138 -0
  32. data/test/test_stream.rb +2 -2
  33. data/test/test_um.rb +427 -34
  34. data/vendor/liburing/.github/workflows/ci.yml +94 -1
  35. data/vendor/liburing/.github/workflows/test_build.c +9 -0
  36. data/vendor/liburing/configure +27 -0
  37. data/vendor/liburing/examples/Makefile +6 -0
  38. data/vendor/liburing/examples/helpers.c +8 -0
  39. data/vendor/liburing/examples/helpers.h +5 -0
  40. data/vendor/liburing/liburing.spec +1 -1
  41. data/vendor/liburing/src/Makefile +9 -3
  42. data/vendor/liburing/src/include/liburing/barrier.h +11 -5
  43. data/vendor/liburing/src/include/liburing/io_uring/query.h +41 -0
  44. data/vendor/liburing/src/include/liburing/io_uring.h +50 -0
  45. data/vendor/liburing/src/include/liburing/sanitize.h +16 -4
  46. data/vendor/liburing/src/include/liburing.h +445 -121
  47. data/vendor/liburing/src/liburing-ffi.map +15 -0
  48. data/vendor/liburing/src/liburing.map +8 -0
  49. data/vendor/liburing/src/sanitize.c +4 -1
  50. data/vendor/liburing/src/setup.c +7 -4
  51. data/vendor/liburing/test/232c93d07b74.c +4 -16
  52. data/vendor/liburing/test/Makefile +15 -1
  53. data/vendor/liburing/test/accept.c +2 -13
  54. data/vendor/liburing/test/conn-unreach.c +132 -0
  55. data/vendor/liburing/test/fd-pass.c +32 -7
  56. data/vendor/liburing/test/fdinfo.c +39 -12
  57. data/vendor/liburing/test/fifo-futex-poll.c +114 -0
  58. data/vendor/liburing/test/fifo-nonblock-read.c +1 -12
  59. data/vendor/liburing/test/futex.c +1 -1
  60. data/vendor/liburing/test/helpers.c +99 -2
  61. data/vendor/liburing/test/helpers.h +9 -0
  62. data/vendor/liburing/test/io_uring_passthrough.c +6 -12
  63. data/vendor/liburing/test/mock_file.c +379 -0
  64. data/vendor/liburing/test/mock_file.h +47 -0
  65. data/vendor/liburing/test/nop.c +2 -2
  66. data/vendor/liburing/test/nop32-overflow.c +150 -0
  67. data/vendor/liburing/test/nop32.c +126 -0
  68. data/vendor/liburing/test/pipe.c +166 -0
  69. data/vendor/liburing/test/poll-race-mshot.c +13 -1
  70. data/vendor/liburing/test/recv-mshot-fair.c +81 -34
  71. data/vendor/liburing/test/recvsend_bundle.c +1 -1
  72. data/vendor/liburing/test/resize-rings.c +2 -0
  73. data/vendor/liburing/test/ring-query.c +322 -0
  74. data/vendor/liburing/test/ringbuf-loop.c +87 -0
  75. data/vendor/liburing/test/runtests.sh +2 -2
  76. data/vendor/liburing/test/send-zerocopy.c +43 -5
  77. data/vendor/liburing/test/send_recv.c +102 -32
  78. data/vendor/liburing/test/shutdown.c +2 -12
  79. data/vendor/liburing/test/socket-nb.c +3 -14
  80. data/vendor/liburing/test/socket-rw-eagain.c +2 -12
  81. data/vendor/liburing/test/socket-rw-offset.c +2 -12
  82. data/vendor/liburing/test/socket-rw.c +2 -12
  83. data/vendor/liburing/test/sqe-mixed-bad-wrap.c +87 -0
  84. data/vendor/liburing/test/sqe-mixed-nop.c +82 -0
  85. data/vendor/liburing/test/sqe-mixed-uring_cmd.c +153 -0
  86. data/vendor/liburing/test/timestamp.c +56 -19
  87. data/vendor/liburing/test/vec-regbuf.c +2 -4
  88. data/vendor/liburing/test/wq-aff.c +7 -0
  89. metadata +24 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff89f34d541e086f8016156d4b5290a6a2fdc94292f04e7a3104ef9e7cda256d
4
- data.tar.gz: 01dbe57b83effbab744fbd07461dcd803246a88bbf3ce1aeaf1e4eace32fd0ad
3
+ metadata.gz: 320cde6219f737bd65911d6b860852e1d706a20d807f68e97a103254d27a6c11
4
+ data.tar.gz: 2a5c40b6121dd4bc25bcfaf0852d56425f398b43660ccb86d883c5f7b2f68dcc
5
5
  SHA512:
6
- metadata.gz: ca0e44f1121384634b4234b2cd49643f87e8255e77eb250f64fb62be8bcdcb18e6a82480e5da003322c941c9ae2def119a048797d53bc064c4e1f77796b82c4d
7
- data.tar.gz: 322090fd12498525d303b63f66ec1c559ed9933e89e74d3b01c9cc5c0f3f1dcee951c767625690c288478d5e460248418bbd693fbd7c31146c7aff76cf545a5d
6
+ metadata.gz: b6940030d3f45f731c2b2e8a853193c4ef46e815b84848fc6a310605e00bfd10dd633ff952fc324f33dd4748c82d72379ddf7e91c0c0020006cacf1a2a6a83cb
7
+ data.tar.gz: 60d92ed67095e67e7a36f329e5131a853dff9f4afde843c8022de88ee3613e97e6f032479ee3090870f6a00804d3863e70968e78e92a1753ced3f8baf0a11df2
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
- # 0.19.1 2025-01-03
1
+ # 0.20.0 2025-11-26
2
+
3
+ - Add `UM.pidfd_open`, `UM.pidfd_send_signal` methods
4
+ - Add `#waitid`, `#waitid_status` methods, remove `#waitpid`
5
+ - Set minimal kernel version to 6.7
6
+ - Add `UM::Error` exception class
7
+ - Add support for `IO::Buffer` in all I/O methods
8
+ - Fix and improve mutex and queue implementations
9
+ - Add UM.debug method
10
+ - Implement Fiber scheduler (WIP)
11
+
12
+ # 0.19.1 2025-11-03
2
13
 
3
14
  - Add `RB_GC_GUARD` in `process_runqueue_op`
4
15
 
data/TODO.md CHANGED
@@ -37,7 +37,6 @@ Some resources:
37
37
  - https://github.com/socketry/async/blob/main/context/getting-started.md
38
38
  - https://github.com/socketry/async/blob/main/context/scheduler.md
39
39
  - https://github.com/socketry/async/blob/main/lib/async/scheduler.rb#L28
40
- -
41
40
 
42
41
  ## useful concurrency tools
43
42
 
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/inline'
4
+
5
+ gemfile do
6
+ source 'https://rubygems.org'
7
+ gem 'benchmark'
8
+ gem 'benchmark-ips'
9
+ end
10
+
11
+ require 'benchmark/ips'
12
+
13
+ r, w = IO.pipe
14
+
15
+ class IO
16
+ def __fd__
17
+ @__fd__ ||= fileno
18
+ end
19
+ end
20
+
21
+ @map = ObjectSpace::WeakMap.new
22
+
23
+ def cached_fileno(r)
24
+ @map[r] ||= r.fileno
25
+ end
26
+
27
+ Benchmark.ips do |x|
28
+ x.report('IO#fileno') { r.fileno }
29
+ x.report('cached_fileno') { cached_fileno(r) }
30
+ x.report('__fd__') { r.__fd__ }
31
+
32
+ x.compare!(order: :baseline)
33
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/inline'
4
+
5
+ gemfile do
6
+ source 'https://rubygems.org'
7
+ gem 'uringmachine', path: '..'
8
+ gem 'benchmark'
9
+ gem 'benchmark-ips'
10
+ end
11
+
12
+ require 'benchmark/ips'
13
+ require 'uringmachine'
14
+ require 'thread'
15
+
16
+ COUNT = 10
17
+ CONCURRENCY = (ENV['CONCURRENCY'] || 4).to_i
18
+
19
+ p(CONCURRENCY: CONCURRENCY)
20
+
21
+ STRING = "foo...bar"
22
+ REGEXP = /foo(.+)bar/
23
+
24
+ def threads_setup
25
+ @threads_mutex = Mutex.new
26
+ @threads_start = Queue.new
27
+ @threads_done = Queue.new
28
+ @threads = CONCURRENCY.times.map {
29
+ Thread.new do
30
+ loop do
31
+ @threads_start.shift
32
+ COUNT.times do
33
+ @threads_mutex.synchronize do
34
+ COUNT.times do
35
+ STRING.match(REGEXP)[1]
36
+ end
37
+ end
38
+ end
39
+ @threads_done << true
40
+ end
41
+ end
42
+ }
43
+ end
44
+
45
+ def threads_run
46
+ @threads_start << true
47
+ @threads_done.shift
48
+ end
49
+
50
+ def um_setup
51
+ @um_machine = UM.new
52
+ @um_mutex = UM::Mutex.new
53
+ @um_start = UM::Queue.new
54
+ @um_done = UM::Queue.new
55
+ @fibers = CONCURRENCY.times.map {
56
+ @um_machine.spin do
57
+ loop do
58
+ @um_machine.shift(@um_start)
59
+ COUNT.times do
60
+ @um_machine.synchronize(@um_mutex) do
61
+ COUNT.times do
62
+ STRING.match(REGEXP)[1]
63
+ end
64
+ end
65
+ end
66
+ @um_machine.push(@um_done, true)
67
+ end
68
+ end
69
+ }
70
+ end
71
+
72
+ def um_run
73
+ @um_machine.push(@um_start, true)
74
+ @um_machine.shift(@um_done)
75
+ end
76
+
77
+ threads_setup
78
+ um_setup
79
+
80
+ Benchmark.ips do |x|
81
+ x.report("threads") { @threads_run }
82
+ x.report("UM") { @um_run }
83
+
84
+ x.compare!(order: :baseline)
85
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/inline'
4
+
5
+ gemfile do
6
+ source 'https://rubygems.org'
7
+ gem 'uringmachine', path: '..'
8
+ gem 'benchmark'
9
+ gem 'benchmark-ips'
10
+ end
11
+
12
+ require 'benchmark/ips'
13
+ require 'uringmachine'
14
+ require 'thread'
15
+
16
+ def threads_setup
17
+ @threads_mutex = Mutex.new
18
+ end
19
+
20
+ def um_setup
21
+ @um_machine = UM.new
22
+ @um_mutex = UM::Mutex.new
23
+ end
24
+
25
+ threads_setup
26
+ um_setup
27
+
28
+ Benchmark.ips do |x|
29
+ x.report("threads") { @threads_mutex.synchronize { } }
30
+ x.report("UM") { @um_machine.synchronize(@um_mutex) {} }
31
+
32
+ x.compare!(order: :baseline)
33
+ end
data/examples/bm_queue.rb CHANGED
@@ -12,17 +12,18 @@ require 'benchmark/ips'
12
12
  require 'uringmachine'
13
13
 
14
14
  COUNT = 1000
15
- NUM_PRODUCERS = 2
16
- NUM_CONSUMERS = 10
15
+ NUM_PRODUCERS = 8
16
+ NUM_CONSUMERS = 8
17
+
18
+ @queue = Queue.new
19
+ @done = Queue.new
17
20
 
18
21
  def run_threads
19
- queue = Queue.new
20
- done = Queue.new
21
22
 
22
23
  NUM_PRODUCERS.times do
23
24
  Thread.new do
24
- COUNT.times { queue << rand(1000) }
25
- done << true
25
+ COUNT.times { @queue << rand(1000) }
26
+ @done << true
26
27
  end
27
28
  end
28
29
 
@@ -30,65 +31,64 @@ def run_threads
30
31
  NUM_CONSUMERS.times do
31
32
  Thread.new do
32
33
  loop do
33
- item = queue.shift
34
+ item = @queue.shift
34
35
  break if item.nil?
35
36
 
36
37
  total += item
37
38
  end
38
- done << true
39
+ @done << true
39
40
  end
40
41
  end
41
42
 
42
43
  # wait for producers
43
- NUM_PRODUCERS.times { done.shift }
44
+ NUM_PRODUCERS.times { @done.shift }
44
45
 
45
46
  # stop and wait for consumers
46
47
  NUM_CONSUMERS.times do
47
- queue << nil
48
- done.shift
48
+ @queue << nil
49
+ @done.shift
49
50
  end
50
51
 
51
52
  total
52
53
  end
53
54
 
54
- def run_um
55
- machine = UM.new
56
- queue = UM::Queue.new
57
- done = UM::Queue.new
55
+ @machine = UM.new
56
+ @um_queue = UM::Queue.new
57
+ @um_done = UM::Queue.new
58
58
 
59
+ def run_um
59
60
  NUM_PRODUCERS.times do
60
- machine.spin do
61
- COUNT.times { machine.push(queue, rand(1000)) }
62
- machine.push(done, true)
61
+ @machine.spin do
62
+ COUNT.times { @machine.push(@um_queue, rand(1000)) }
63
+ @machine.push(@um_done, true)
63
64
  end
64
65
  end
65
66
 
66
67
  total = 0
67
68
  NUM_CONSUMERS.times do
68
- machine.spin do
69
+ @machine.spin do
69
70
  loop do
70
- item = machine.shift(queue)
71
+ item = @machine.shift(@um_queue)
71
72
  break if item.nil?
72
73
 
73
74
  total += item
74
75
  end
75
- machine.push(done, true)
76
+ @machine.push(@um_done, true)
76
77
  end
77
78
  end
78
79
 
79
80
  # wait for producers
80
- NUM_PRODUCERS.times { machine.shift(done) }
81
+ NUM_PRODUCERS.times { @machine.shift(@um_done) }
81
82
 
82
83
  # stop and wait for consumers
83
84
  NUM_CONSUMERS.times do
84
- machine.push(queue, nil)
85
- machine.shift(done)
85
+ @machine.push(@um_queue, nil)
86
+ @machine.shift(@um_done)
86
87
  end
87
88
 
88
89
  total
89
90
  end
90
91
 
91
-
92
92
  # puts "running"
93
93
  # res = run_threads
94
94
  # p threads: res
@@ -98,14 +98,13 @@ end
98
98
  # p fibers: res
99
99
  # }
100
100
 
101
-
102
101
  # __END__
103
102
 
104
103
  Benchmark.ips do |x|
105
- x.config(:time => 5, :warmup => 2)
104
+ x.config(:time => 10, :warmup => 3)
106
105
 
107
106
  x.report("threads") { run_threads }
108
107
  x.report("UM") { run_um }
109
108
 
110
- x.compare!
109
+ x.compare!(order: :baseline)
111
110
  end
data/examples/bm_send.rb CHANGED
@@ -71,10 +71,6 @@ def um_send_bundle
71
71
  @machine.send_bundle(@server_fd, @bgid, @parts)
72
72
  end
73
73
 
74
- # um_send_bundle
75
- # 10.times { @machine.snooze }
76
- # exit
77
-
78
74
  p(STR_COUNT:, STR_SIZE:)
79
75
 
80
76
  Benchmark.ips do |x|
@@ -82,5 +78,6 @@ Benchmark.ips do |x|
82
78
  x.report('UM#write') { um_write }
83
79
  x.report('UM#send') { um_send }
84
80
  x.report('UM#send_bundle') { um_send_bundle }
85
- x.compare!
81
+
82
+ x.compare!(order: :baseline)
86
83
  end
@@ -15,37 +15,19 @@ ITERATIONS = 1000
15
15
 
16
16
  $machine = UringMachine.new
17
17
 
18
- def run_snooze
18
+ def run_snooze_um
19
19
  count = 0
20
- main = Fiber.current
21
20
 
22
- f1 = Fiber.new do
23
- loop do
24
- count += 1
25
- if count == ITERATIONS
26
- $machine.schedule(main, nil)
27
- break
28
- else
29
- $machine.snooze
30
- end
31
- end
32
- end
21
+ f1 = $machine.spin {
22
+ ITERATIONS.times { count += 1; $machine.snooze }
23
+ }
24
+ f2 = $machine.spin {
25
+ ITERATIONS.times { count += 1; $machine.snooze }
26
+ }
33
27
 
34
- f2 = Fiber.new do
35
- loop do
36
- count += 1
37
- if count == ITERATIONS
38
- $machine.schedule(main, nil)
39
- break
40
- else
41
- $machine.snooze
42
- end
43
- end
44
- end
28
+ $machine.join(f1, f2)
45
29
 
46
- $machine.schedule(f1, nil)
47
- $machine.schedule(f2, nil)
48
- $machine.yield
30
+ count
49
31
  end
50
32
 
51
33
  def run_raw_transfer
@@ -53,36 +35,32 @@ def run_raw_transfer
53
35
  main = Fiber.current
54
36
  f2 = nil
55
37
  f1 = Fiber.new do
56
- loop do
38
+ ITERATIONS.times do
57
39
  count += 1
58
- if count == ITERATIONS
59
- main.transfer(nil)
60
- break
61
- else
62
- f2.transfer(nil)
63
- end
40
+ f2.transfer(nil)
64
41
  end
65
42
  end
66
43
 
67
44
  f2 = Fiber.new do
68
- loop do
45
+ ITERATIONS.times do
69
46
  count += 1
70
- if count == ITERATIONS
71
- main.transfer(nil)
72
- break
73
- else
74
- f1.transfer(nil)
75
- end
47
+ f1.transfer(nil)
76
48
  end
49
+ main.transfer(nil)
77
50
  end
78
51
 
79
52
  f1.transfer(nil)
53
+
54
+ count
80
55
  end
81
56
 
57
+ p run_snooze_um: run_snooze_um
58
+ p run_raw_transfer: run_raw_transfer
59
+
82
60
  bm = Benchmark.ips do |x|
83
61
  x.config(:time => 5, :warmup => 2)
84
62
 
85
- x.report("snooze") { run_snooze }
63
+ x.report("snooze_um") { run_snooze_um }
86
64
  x.report("raw transfer") { run_raw_transfer }
87
65
 
88
66
  x.compare!
@@ -1,71 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../lib/uringmachine'
4
- require_relative '../lib/uringmachine/fiber_scheduler'
3
+ require 'bundler/setup'
4
+
5
+ require 'uringmachine'
6
+ require 'uringmachine/fiber_scheduler'
5
7
  require 'net/http'
6
8
 
7
- machine = UringMachine.new
8
- scheduler = UM::FiberScheduler.new(machine)
9
+ $machine = UringMachine.new
10
+ scheduler = UM::FiberScheduler.new($machine)
9
11
  Fiber.set_scheduler scheduler
10
12
 
11
13
  i, o = IO.pipe
12
14
 
13
15
  f1 = Fiber.schedule do
14
- # sleep 0.4
15
- # o.write 'Hello, world!'
16
- # o.close
16
+ puts "Hello from fiber 1!!!"
17
17
  end
18
18
 
19
19
  f2 = Fiber.schedule do
20
- # puts "hi"
21
- # 10.times do
22
- # sleep 0.1
23
- # puts "."
24
- # end
20
+ puts "Hello from fiber 2!!!"
25
21
  end
26
22
 
27
- # Fiber.schedule do
28
- # scheduler.block(:wait)
29
- # end
30
-
31
23
  f3 = Fiber.schedule do
32
- # message = i.read
33
- # puts message
34
- # rescue => e
35
- # scheduler.p e
36
- # scheduler.p e.backtrace
24
+ o.write 'hello'
25
+ puts "wrote it!"
26
+ o.close
37
27
  end
38
28
 
39
29
  f4 = Fiber.schedule do
40
- puts '*' * 40
41
- # tcp = TCPSocket.new('noteflakes.com', 80)
42
- # tcp.timeout = 10
43
- # scheduler.p tcp
44
- # tcp << "GET / HTTP/1.1\r\nHost: noteflakes.com\r\n\r\n"
45
- # s = tcp.read
46
- # scheduler.p s: s
47
- ret = Net::HTTP.get('noteflakes.com', '/ping')
48
- scheduler.p ret: ret
49
- rescue => e
50
- scheduler.p e
51
- scheduler.p e.backtrace
30
+ str = i.read
31
+ puts "got: #{str}"
52
32
  end
53
33
 
54
- scheduler.join(f1, f2, f3, f4)
55
-
56
- __END__
57
-
58
- stdout_fd = STDOUT.fileno
59
- stdin_fd = STDIN.fileno
60
- machine.write(stdout_fd, "Hello, world!\n")
61
-
62
- loop do
63
- machine.write(stdout_fd, "Say something: ")
64
- buf = +''
65
- res = machine.read(stdin_fd, buf, 8192)
66
- if res > 0
67
- machine.write(stdout_fd, "You said: #{buf}")
68
- else
69
- break
70
- end
71
- end
34
+ # scheduler.join
35
+ # Fiber.set_scheduler(nil)
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'uringmachine'
6
+ require 'uringmachine/fiber_scheduler'
7
+ require 'net/http'
8
+
9
+ $machine = UringMachine.new
10
+ scheduler = UM::FiberScheduler.new($machine)
11
+ Fiber.set_scheduler scheduler
12
+
13
+ p parent: Fiber.scheduler
14
+ p Fiber.current
15
+
16
+ pid = fork do
17
+ Fiber.scheduler.post_fork
18
+ Fiber.set_scheduler nil
19
+ p child: Fiber.scheduler
20
+ # Fiber.scheduler.post_fork
21
+ end
22
+
23
+ Process.wait(pid)
24
+ p :done
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/uringmachine'
4
+ require 'openssl'
5
+
6
+ HOST = ARGV[0]
7
+ PORT = ARGV[1].to_i
8
+
9
+ machine = UringMachine.new
10
+
11
+ conn_fd = machine.socket(Socket::AF_INET, Socket::SOCK_STREAM, 0, 0);
12
+ machine.connect(conn_fd, HOST, PORT)
13
+
14
+ class FakeIO < File
15
+ def initialize(machine, fd)
16
+ @machine = machine
17
+ @fd = fd
18
+ end
19
+
20
+ def nonblock=(x)
21
+ p 'nonblock=': x
22
+ end
23
+
24
+ def sync
25
+ p sync: true
26
+ true
27
+ end
28
+
29
+ def write(buf)
30
+ p write: buf
31
+ @machine.write(fd, buf)
32
+ end
33
+
34
+ def read(maxlen = 4096, buf = nil)
35
+ p read: [maxlen, buf]
36
+ buf ||= +''
37
+ _res = @machine.read(@fd, buf, maxlen)
38
+ buf
39
+ end
40
+ end
41
+
42
+ conn_io = FakeIO.new(machine, conn_fd)
43
+
44
+ ssl_io = OpenSSL::SSL::SSLSocket.new(conn_io)
45
+
46
+ stdin_fd = STDIN.fileno
47
+ stdout_fd = STDOUT.fileno
48
+
49
+ f_writer = Fiber.new do
50
+ bgidw = machine.setup_buffer_ring(4096, 1024)
51
+ machine.read_each(stdin_fd, bgidw) do |buf|
52
+ ssl_io.write(buf)
53
+ end
54
+ end
55
+ machine.schedule(f_writer, nil)
56
+
57
+ f_reader = Fiber.new do
58
+ buffer = +''
59
+ loop do
60
+ ssl_io.read(4096, buffer)
61
+ break if buffer.empty?
62
+
63
+ machine.write(stdout_fd, buf)
64
+ end
65
+ end
66
+ machine.schedule(f_reader, nil)
67
+
68
+ trap('SIGINT') { exit! }
69
+ loop do
70
+ machine.sleep(60)
71
+ end
data/ext/um/extconf.rb CHANGED
@@ -19,19 +19,12 @@ def get_config
19
19
  version, major_revision, distribution = m[1].to_i, m[2].to_i, m[4]
20
20
 
21
21
  combined_version = version.to_i * 100 + major_revision.to_i
22
- raise "UringMachine requires kernel version 6.4 or newer!" if combined_version < 604
22
+ raise "UringMachine requires kernel version 6.7 or newer!" if combined_version < 607
23
23
 
24
24
  {
25
25
  kernel_version: combined_version,
26
- submit_all_flag: combined_version >= 518,
27
- coop_taskrun_flag: combined_version >= 519,
28
- single_issuer_flag: combined_version >= 600,
29
26
  prep_bind: combined_version >= 611,
30
- prep_listen: combined_version >= 611,
31
- prep_cmd_sock: combined_version >= 607,
32
- prep_futex: combined_version >= 607,
33
- prep_waitid: combined_version >= 607,
34
- prep_read_multishot: combined_version >= 607
27
+ prep_listen: combined_version >= 611
35
28
  }
36
29
  end
37
30
 
@@ -56,15 +49,12 @@ if !find_library('uring', nil, File.join(liburing_path, 'src'))
56
49
  raise "Couldn't find liburing.a"
57
50
  end
58
51
 
52
+ have_func("rb_process_status_new")
53
+
59
54
  $defs << "-DUM_KERNEL_VERSION=#{config[:kernel_version]}"
60
- $defs << '-DHAVE_IORING_SETUP_SUBMIT_ALL' if config[:submit_all_flag]
61
- $defs << '-DHAVE_IORING_SETUP_COOP_TASKRUN' if config[:coop_taskrun_flag]
62
55
  $defs << '-DHAVE_IO_URING_PREP_BIND' if config[:prep_bind]
63
56
  $defs << '-DHAVE_IO_URING_PREP_LISTEN' if config[:prep_listen]
64
- $defs << '-DHAVE_IO_URING_PREP_CMD_SOCK' if config[:prep_cmd_sock]
65
- $defs << '-DHAVE_IO_URING_PREP_FUTEX' if config[:prep_futex]
66
- $defs << '-DHAVE_IO_URING_PREP_WAITID' if config[:prep_waitid]
67
- $defs << '-DHAVE_IO_URING_PREP_READ_MULTISHOT' if config[:prep_read_multishot]
57
+
68
58
  $CFLAGS << ' -Wno-pointer-arith'
69
59
 
70
60
  CONFIG['optflags'] << ' -fno-strict-aliasing'