yes
Right now, it happens every time. But it didn’t happen when I first updated the sclockadj a few days ago. So its strange. Maybe I reboot and it stops happening.
[quote=“Patrick, post:16, topic:732”]
def self.make_jumps amount, min, max, jumps = []
puts "debug 28b: amount=#{amount}. min=#{min}. max=#{max}"
Would be useful to also look into the variable “jumps”.
if debugicounter > 10 then abort("debug 28c exit") end
This is a good idea. Actually, what could cause the 100% CPU is a loop that has very little to do and is endless. But I would guess, that the above loop that actually does the work could be the one in question.[/quote]
Yep. It seems that is the loop that’s endless.
$ sudo /usr/lib/sclockadj --verbose --no-debug --no-first-wait --move-min 500000 --move-max 500000 --wait-min 1000000000 --wait-max 1000000000 --add 89780310937779
debug 1
debug 2
debug 3
debug 4
debug 14
debug 30
debug 5
debug 6
debug 7
debug 12
debug 8
debug 9
debug 13
debug 31
debug 15: amount=89780310937779. move_min=500000. move_max=500000. wait_min=1000000000.
Running with PID: 10014
debug 16
debug 28b: amount=89780310937779. min=500000. max=500000. jumps=[]
debug 29. Amount=89780310937779. max=500000. min=500000. jumps=[]
debug 29b. random_jump=500000
debug 29. Amount=89780310437779. max=500000. min=500000. jumps=[500000]
debug 29b. random_jump=500000
debug 29. Amount=89780309937779. max=500000. min=500000. jumps=[500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780309437779. max=500000. min=500000. jumps=[500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780308937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780308437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780307937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780307437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780306937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780306437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780305937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780305437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780304937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780304437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780303937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780303437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780302937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780302437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780301937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780301437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780300937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780300437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780299937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780299437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780298937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780298437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780297937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780297437779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 29. Amount=89780296937779. max=500000. min=500000. jumps=[500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000]
debug 29b. random_jump=500000
debug 28c exit
with
#!/usr/bin/env ruby
puts "debug 1"
module SneakyClockAdjusterCLI
puts "debug 2"
require 'optparse'
puts "debug 3"
require 'ostruct'
puts "debug 4"
def self.parse args
puts "debug 5"
options = OpenStruct.new
options.add_or_substract = :add
options.amount = nil
options.move_min = nil
options.move_max = nil
options.wait_min = nil
options.wait_max = nil
options.first_wait = false
options.verbose = true
options.debug = false
options.systohc = false
puts "debug 6"
opt_parser = OptionParser.new do |opts|
opts.banner = ""
opts.separator "Specific options:"
puts "debug 7"
opts.on("--add num", Integer, "(Required) Nanoseconds to add") do |v|
puts "debug 8"
options.add_or_substract = :add
options.amount = v
puts "debug 9"
end
opts.on("--subtract num", Integer, "(Required) Nanoseconds to subtract") do |v|
puts "debug 10"
options.add_or_substract = :subtract
options.amount = v
puts "debug 11"
end
opts.on("--wait-min num", Integer, "(Required) Minimum random seconds to wait") do |v|
options.wait_min = v
end
opts.on("--wait-max num", Integer, "(Required) Maximum random seconds to wait") do |v|
options.wait_max = v
end
opts.on("--move-min num", Integer, "(Required) Minimum random nanoseconds to change") do |v|
options.move_min = v
end
opts.on("--move-max num", Integer, "(Required) Maximum random nanoseconds to change") do |v|
options.move_max = v
end
opts.on("--[no-]first-wait", "Wait before first change?") do |v|
options.first_wait = v
end
opts.on("--[no-]verbose", "Run Verbosely?") do |v|
options.verbose = v
end
opts.on("--[no-]debug", "Debug messages. Don't change date.") do |v|
options.debug = v
end
opts.on("--[no-]systohc", "Update hardware clock.") do |v|
options.systohc = v
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end
puts "debug 12"
opt_parser.parse!
if options.amount == nil then puts opt_parser; exit 1 end
if options.move_min == nil then puts opt_parser; exit 1 end
if options.move_max == nil then puts opt_parser; exit 1 end
if options.wait_min == nil then puts opt_parser; exit 1 end
if options.wait_max == nil then puts opt_parser; exit 1 end
if options.amount == nil then puts opt_parser; exit 1 end
if options.amount <= 0 then raise OptionParser::InvalidArgument, "Input must be positive!" end
if options.wait_min < 0 then raise OptionParser::InvalidArgument, "Input must be positive!" end
if options.wait_max < options.wait_min then raise OptionParser::InvalidArgument, "Max must > min!" end
if options.move_min < 0 then raise OptionParser::InvalidArgument, "Input must be positive!" end
if options.move_max < options.move_min then raise OptionParser::InvalidArgument, "Max must > min!" end
puts "debug 13"
return options
end # self.parse
end # module SneakyClockAdjusterCLI
module SneakyClockAdjuster
puts "debug 14"
require 'openssl'
require 'securerandom'
require 'bigdecimal'
require 'bigdecimal/util'
require 'inline'
def self.execute add_or_substract, amount, move_min, move_max, wait_min, wait_max, first_wait = false, verbose = true, debug = false, systohc = false
puts "debug 15: amount=#{amount}. move_min=#{move_min}. move_max=#{move_max}. wait_min=#{wait_min}."
puts "Running with PID: #{Process.pid}" if verbose
Kernel.trap("TERM") do
puts "Exiting..."
exit 143
end
Kernel.trap("INT") do
puts "Exiting..."
exit 130
end
puts "debug 16"
jumps = make_jumps amount, move_min, move_max
puts "debug 16b: jumps="+jumps.inspect
jumps_c = jumps.count
intervals = make_intervals jumps_c, wait_min, wait_max
if not first_wait then intervals[0] = 0 end
if debug
puts "DEBUG: Using these sleep intervals: #{intervals}"
puts "DEBUG: with these time jumps: #{jumps}"
end
puts "debug 17"
c = Cinline.new
puts "debug 18"
jumps.each_index do |index|
if verbose
puts "---"
puts "Iteration: #{index+1} of #{jumps_c}"
puts "debug 19"
end
wait_ns = intervals[index]
wait_s = wait_ns.to_f / 1000000000
jump_ns = jumps[index]
jump_s = jump_ns.to_f / 1000000000
puts "debug 20"
if wait_ns > 0 then
puts "Waiting #{wait_ns} nanoseconds [#{wait_s} seconds]" if verbose
sleep(wait_s)
puts "debug 21"
end
if verbose
puts "debug 22"
print "Aproximate system date with nanoseconds: "
puts %x[echo "$(date) | $(date +%N)"]
end
if add_or_substract == :add then
puts "Adding #{jump_ns} nanoseconds [#{jump_s} seconds]" if verbose
else
puts "Subtracting #{jump_ns} nanoseconds [#{jump_s} seconds]" if verbose
jump_ns = -jump_ns
puts "debug 23"
end
if not debug
puts "debug 24"
c_return_code = c.getAndSet(jump_ns)
puts "c_return_code: #{c_return_code}" if verbose
if c_return_code != 0 then
warn "ERROR: c_return_code was: #{c_return_code}"
exit c_return_code
end
end
if systohc then
cmd = "hwclock --systohc"
puts "Set hwclock with: #{cmd}" if verbose
system cmd unless debug
puts "debug 25"
end
if verbose
print "Aproximate system date with nanoseconds: "
puts %x[echo "$(date) | $(date +%N)"]
puts "debug 26"
end
end # jumps.each_index
if verbose
puts "---"
puts "Done! Exiting..."
end
end
def self.make_intervals count, min, max, intervals = []
count.times do
puts "debug 28"
intervals << (SecureRandom.random_number max-min+1) + min
end
return intervals
end
def self.make_jumps amount, min, max, jumps = []
puts "debug 28b: amount=#{amount}. min=#{min}. max=#{max}. jumps="+jumps.inspect
debugicounter = 1
loop do
debugicounter = debugicounter+1
if debugicounter > 30 then abort("debug 28c exit") end
puts "debug 29. Amount=#{amount}. max=#{max}. min=#{min}. jumps="+jumps.inspect
if amount < 1 then return jumps end
if amount < min then return jumps << amount end
if amount - max < 1 then max = amount end
random_jump = (SecureRandom.random_number max-min+1) + min
puts "debug 29b. random_jump=#{random_jump}"
jumps << random_jump
amount -= random_jump
end
puts "debug 29c"
end
end # module SneakyClockAdjuster
class Cinline
inline :C do |builder|
builder.include '<stdio.h>'
builder.include '<time.h>'
builder.include '<sys/time.h>'
builder.c '
int getAndSet(long long addNsec) {
/* receive time adjustment, negative or positive, in nanoseconds */
/* get current time in seconds since epoch + nanoseconds offset */
struct timespec tps; /* tv_sec; tv_nsec */
if( clock_gettime(0, &tps) == -1 ) {
perror( "getclock" );
return EXIT_FAILURE;
}
/* combine seconds and nanoseconds offset to manipulate */
long long nanosecondsSinceEpoch =
(long long)(tps.tv_sec) * 1000000000 + /* convert seconds to nanoseconds */
(long long)(tps.tv_nsec); /* add offset */
long long newNanosecondsSinceEpoch = nanosecondsSinceEpoch += addNsec;
/* separate adjusted nanoseconds since epoch into seconds + nanoseconds offset */
long newNS = newNanosecondsSinceEpoch % 1000000000; /* pulls out nanoseconds */
long newS = newNanosecondsSinceEpoch / 1000000000; /* truncates into seconds */
/* set struct with new values; set time */
tps.tv_sec = newS; /* reusing old struct */
tps.tv_nsec = newNS;
if( clock_settime(0, &tps) == -1 ) {
perror( "setclock" );
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
'
end
end
puts "debug 30"
options = SneakyClockAdjusterCLI.parse(ARGV)
puts "debug 31"
SneakyClockAdjuster.execute options.add_or_substract, options.amount, options.move_min, options.move_max, options.wait_min, options.wait_max, options.first_wait, options.verbose, options.debug