To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit 031c6307 authored by Javad Ebrahimian Amiri's avatar Javad Ebrahimian Amiri
Browse files

first running collision detection benchmark (seg faults on futex)

parent dc48e635
......@@ -87,10 +87,10 @@ impl Instruction {
| NewStack(_)
| NewThread { .. }
| NewRTThread { .. }
| NewFutex
| NewFutex(_)
| DeleteFutex(_)
| LockFutex(_,_)
| UnlockFutex(_)
| UnlockFutex(_,_)
| AllocAU(_)
| AllocAUHybrid(_,_)
| NewReg(_)
......@@ -202,10 +202,10 @@ impl Instruction {
| NewStack(_)
| NewThread { .. }
| NewRTThread { .. }
| NewFutex
| NewFutex(_)
| DeleteFutex(_)
| LockFutex(_,_)
| UnlockFutex(_)
| UnlockFutex(_,_)
| NotifyThread(_)
| ThreadSetPriority(_, _)
| ThreadClearCPU(_, _)
......@@ -330,10 +330,10 @@ impl Instruction {
| eDelete(_)
| NewThread { .. }
| NewRTThread { .. }
| NewFutex
| NewFutex(_)
| DeleteFutex(_)
| LockFutex(_, _)
| UnlockFutex(_)
| UnlockFutex(_,_)
| NotifyThread(_)
| ThreadSetPriority(_, _)
| ThreadGetPriority(_)
......@@ -454,10 +454,10 @@ impl Instruction {
| NewStack(_)
| NewThread { .. }
| NewRTThread { .. }
| NewFutex
| NewFutex(_)
| DeleteFutex(_)
| LockFutex(_,_)
| UnlockFutex(_)
| UnlockFutex(_,_)
| NotifyThread(_)
| ThreadSetPriority(_,_) // FIXME - Not sure about these
| ThreadGetPriority(_)
......@@ -570,10 +570,10 @@ impl Instruction {
NewStack(_) |
NewThread { .. } |
NewRTThread { .. } |
NewFutex
NewFutex(_)
| DeleteFutex(_)
| LockFutex(_,_)
| UnlockFutex(_)
| UnlockFutex(_,_)
| NotifyThread(_) |
ThreadSetPriority(_,_) |
NewFrameCursor(_) |
......@@ -805,15 +805,15 @@ impl Instruction {
)
}
&Instruction_::NewFutex => format!("NEWFUTEX"),
&Instruction_::NewFutex(init_val) => format!("NEWFUTEX {}", ops[init_val]),
&Instruction_::DeleteFutex(futexref) => {
format!("DELETEFUTEX {}", ops[futexref])
}
&Instruction_::LockFutex(futexref, timeout) => {
format!("LockFUTEX ({}, {})", ops[futexref], ops[timeout])
}
&Instruction_::UnlockFutex(futexref) => {
format!("UNLOCKFUTEX {}", ops[futexref])
&Instruction_::UnlockFutex(futexref, count) => {
format!("UNLOCKFUTEX {}, {}", ops[futexref], ops[count])
}
&Instruction_::NewRTThread {
......@@ -1442,10 +1442,10 @@ pub enum Instruction_ {
AttrIssetCPU(OpIndex, OpIndex),
AttrZeroCPU(OpIndex),
NewFutex,
NewFutex(OpIndex),
DeleteFutex(OpIndex),
LockFutex(OpIndex, OpIndex),
UnlockFutex(OpIndex),
UnlockFutex(OpIndex, OpIndex),
// #[cfg(feature = "realtime")]
/// notify a thread to start running
......
......@@ -3853,6 +3853,7 @@ use std::fs::File;
pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
use std::io::prelude::*;
use std::path;
use compiler::passes::tune_file_name;
let funcs = vm.funcs().read().unwrap();
let func = funcs.get(&fv.func_id).unwrap().read().unwrap();
......@@ -3865,7 +3866,9 @@ pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push(func.name().to_string() + ".S");
let fname = func.name();
let fname = tune_file_name(fname);
file_path.push(fname.clone().to_string() + ".S");
{
let mut file = match File::create(file_path.as_path()) {
Err(why) => panic!(
......@@ -3905,7 +3908,7 @@ pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
{
let mut demangled_path = path::PathBuf::new();
demangled_path.push(&vm.vm_options.flag_aot_emit_dir);
demangled_path.push((*func.name()).clone() + ".demangled.S");
demangled_path.push(fname.clone().to_string() + ".demangled.S");
let mut demangled_file = match File::create(demangled_path.as_path()) {
Err(why) => panic!(
......
......@@ -4003,6 +4003,8 @@ use std::fs::File;
/// emit assembly file for a function version
pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
use compiler::passes::tune_file_name;
// acquire lock and function
let funcs = vm.funcs().read().unwrap();
let func = funcs.get(&fv.func_id).unwrap().read().unwrap();
......@@ -4017,7 +4019,9 @@ pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
// create emit file
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push((*func.name()).clone() + ".S");
let fname = func.name().clone();
let fname = tune_file_name(fname);
file_path.push(fname.clone().to_string() + ".S");
{
let mut file = match File::create(file_path.as_path()) {
Err(why) => panic!(
......@@ -4052,7 +4056,7 @@ pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
{
let mut demangled_path = path::PathBuf::new();
demangled_path.push(&vm.vm_options.flag_aot_emit_dir);
demangled_path.push((*func.name()).clone() + ".demangled.S");
demangled_path.push(fname.clone().to_string() + ".demangled.S");
let mut demangled_file = match File::create(demangled_path.as_path()) {
Err(why) => panic!(
......
......@@ -2883,14 +2883,17 @@ impl<'a> InstructionSelection {
// vm,
// );
// }
Instruction_::NewFutex => {
Instruction_::NewFutex(init_val) => {
trace!("instsel on NewFutex");
let ref val = inst.ops[init_val];
let tmp_val = self.emit_ireg(val, f_content, f_context, vm);
let res = self.get_result_value(node);
self.emit_runtime_entry(
&entrypoints::NEW_FUTEX,
vec![],
vec![tmp_val],
Some(vec![res]),
Some(node),
f_content,
......@@ -2939,18 +2942,22 @@ impl<'a> InstructionSelection {
vm
);
}
Instruction_::UnlockFutex(futexref) => {
Instruction_::UnlockFutex(futexref, count) => {
trace!("instsel on UnlockFutex");
let ref ops = inst.ops;
let ref futexref = ops[futexref];
let ref count = ops[count];
let tmp_futex =
self.emit_ireg(futexref, f_content, f_context, vm);
let tmp_count =
self.emit_ireg(count, f_content, f_context, vm);
self.emit_runtime_entry(
&entrypoints::UNLOCK_FUTEX,
vec![tmp_futex],
vec![tmp_futex, tmp_count],
None,
Some(node),
f_content,
......
......@@ -716,10 +716,10 @@ pub fn estimate_insts_for_ir(inst: &Instruction) -> usize {
NewStack(_)
| NewThread { .. }
| NewRTThread { .. }
| NewFutex
| NewFutex(_)
| DeleteFutex(_)
| LockFutex(_, _)
| UnlockFutex(_)
| UnlockFutex(_,_)
| NotifyThread(_)
| ThreadSetPriority(_, _)
| ThreadGetPriority(_)
......
......@@ -62,9 +62,12 @@ impl CompilerPass for CodeEmission {
/// creates an file to write, panics if the creation fails
fn create_emit_file(name: String, vm: &VM) -> File {
use compiler::passes::tune_file_name;
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push(name);
let name = tune_file_name(Arc::from(name));
file_path.push(&*name);
match File::create(file_path.as_path()) {
Err(why) => panic!(
......
......@@ -25,9 +25,12 @@ use std::path;
use vm::uir_output::{create_emit_directory, EMIT_MUIR};
fn create_emit_file(name: String, vm: &VM) -> File {
use compiler::passes::tune_file_name;
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push(name);
let name = tune_file_name(Arc::from(name));
file_path.push(&*name);
match File::create(file_path.as_path()) {
Err(why) => panic!(
......@@ -55,7 +58,10 @@ impl DotGen {
#[allow(dead_code)]
fn emit_muir_dot(suffix: &str, func: &MuFunctionVersion, vm: &VM) {
use compiler::passes::tune_file_name;
let func_name = func.name();
let func_name = tune_file_name(func_name);
// create emit directory
create_emit_directory(vm);
......
......@@ -142,3 +142,13 @@ pub trait CompilerPass {
) {
}
}
pub fn tune_file_name(fname: Arc<String>) -> Arc<String> {
let ln = fname.len();
if ln < 200 {
return fname
}
let res = String::from(fname.get(0..100).unwrap()) + fname.get((ln-100)..ln).unwrap();
return Arc::from(res)
}
......@@ -91,10 +91,10 @@ fn is_suitable_child(inst: &Instruction) -> bool {
| NewStack(_)
| NewThread { .. }
| NewRTThread { .. }
| NewFutex
| NewFutex(_)
| DeleteFutex(_)
| LockFutex(_, _)
| UnlockFutex(_)
| UnlockFutex(_,_)
| NotifyThread(_)
| ThreadSetPriority(_, _)
| ThreadGetPriority(_)
......
......@@ -26,9 +26,12 @@ use vm::uir_output::create_emit_directory;
pub const EMIT_MUIR: bool = true;
fn create_emit_file(name: String, vm: &VM) -> File {
use compiler::passes::tune_file_name;
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push(name);
let name = tune_file_name(Arc::from(name));
file_path.push(&*name);
match File::create(file_path.as_path()) {
Err(why) => panic!(
......@@ -54,9 +57,13 @@ impl UIRGen {
}
}
#[allow(dead_code)]
fn emit_uir(suffix: &str, func_ver: &MuFunctionVersion, vm: &VM) {
use compiler::passes::tune_file_name;
let func_ver_name = func_ver.name();
let func_ver_name = tune_file_name(func_ver_name);
// create emit directory
create_emit_directory(vm);
......
......@@ -444,7 +444,7 @@ lazy_static! {
lazy_static! {
pub static ref NEW_FUTEX: RuntimeEntrypoint = RuntimeEntrypoint::new(
"muentry_futex_new",
vec![],
vec![UINT64_TYPE.clone()],
vec![ADDRESS_TYPE.clone()]
);
pub static ref DELETE_FUTEX: RuntimeEntrypoint = RuntimeEntrypoint::new(
......@@ -459,7 +459,7 @@ lazy_static! {
);
pub static ref UNLOCK_FUTEX: RuntimeEntrypoint = RuntimeEntrypoint::new(
"muentry_futex_unlock",
vec![ADDRESS_TYPE.clone()],
vec![ADDRESS_TYPE.clone(), UINT64_TYPE.clone()],
vec![]
);
}
......
......@@ -20,8 +20,10 @@ use super::*;
use super::futex_rtmu_linux::*;
#[no_mangle]
pub extern "C" fn muentry_futex_new() -> Address {
sys_rtmu_futex::new()
pub extern "C" fn muentry_futex_new(init_val: u64) -> Address {
let res = sys_rtmu_futex::new(init_val as u32);
debug!("muentry_futex_new.futex_addr: {}", res);
res
}
#[no_mangle]
......@@ -31,12 +33,14 @@ pub extern "C" fn muentry_futex_delete(f: Address) {
#[no_mangle]
pub extern "C" fn muentry_futex_lock(futex_addr: Address, timeout_ns: u64) {
debug!("muentry_futex_lock.futex_addr: {}", futex_addr);
let the_futex: &mut sys_rtmu_futex = unsafe { futex_addr.to_ref_mut() };
the_futex.lock(timeout_ns);
}
#[no_mangle]
pub extern "C" fn muentry_futex_unlock(futex_addr: Address) {
pub extern "C" fn muentry_futex_unlock(futex_addr: Address, count: u64) {
debug!("muentry_futex_unlock.futex_addr: {}", futex_addr);
let the_futex: &mut sys_rtmu_futex = unsafe { futex_addr.to_ref_mut() };
the_futex.unlock();
the_futex.unlock(count);
}
......@@ -27,9 +27,9 @@ pub(super) struct sys_rtmu_futex {
}
impl sys_rtmu_futex {
pub fn new() -> Address {
pub fn new(init_val: u32) -> Address {
let fbox = Box::new(sys_rtmu_futex {
mem: AtomicU32::new(0)
mem: AtomicU32::new(init_val)
});
Address::from_mut_ptr(Box::into_raw(fbox))
......@@ -65,7 +65,7 @@ impl sys_rtmu_futex {
}
}
pub fn unlock(&mut self) {
pub fn unlock(&mut self, count: u64) {
let my_tid = os_gettid();
match self.mem.compare_exchange(
my_tid as u32,
......@@ -82,7 +82,8 @@ impl sys_rtmu_futex {
id
);
sys_futex_unlock_slowpath(
&mut self.mem as *const AtomicU32 as *const u32 as *mut u32
&mut self.mem as *const AtomicU32 as *const u32 as *mut u32,
count
);
}
}
......@@ -130,7 +131,7 @@ fn sys_futex_lock_slowpath(futex_ptr: *mut u32, timeout_ns: u64) {
trace!("FUTEX.lock slowpath aquired #{:#?}", futex_ptr);
}
fn sys_futex_unlock_slowpath(futex_ptr: *mut u32) {
fn sys_futex_unlock_slowpath(futex_ptr: *mut u32, count: u64) {
let null_ts: *mut libc::timespec = std::ptr::null_mut();
let null_cl: *mut libc::c_long = std::ptr::null_mut();
......@@ -139,7 +140,7 @@ fn sys_futex_unlock_slowpath(futex_ptr: *mut u32) {
libc::SYS_futex,
futex_ptr,
libc::FUTEX_UNLOCK_PI,
0,
count,
null_ts,
null_cl,
0
......
......@@ -70,7 +70,7 @@ impl MuThread {
trace!("mu_thread_launch(");
trace!("id: {}", id);
trace!("attr: {:#?}", attr);
trace!("stack:");
trace!("stack (Add: {}) ->:", Address::from_ref(&stack));
stack.print_stack(Some(20));
trace!("tls: {}", user_tls);
trace!("exc: {:#?}", exception);
......
......@@ -3157,12 +3157,14 @@ extern "C" fn _forwarder__MuIRBuilder__new_yield(
extern "C" fn _forwarder__MuIRBuilder__new_newfutex(
b: *mut CMuIRBuilder,
id: CMuID,
init_val: CMuVarNode,
result_id: CMuID
) {
let mut _arg_b = from_MuIRBuilder_ptr(b);
let mut _arg_id = from_MuID(id);
let mut _arg_iv = from_MuID(init_val);
let mut _arg_result_id = from_MuID(result_id);
unsafe { (*_arg_b).new_newfutex(_arg_id, _arg_result_id) };
unsafe { (*_arg_b).new_newfutex(_arg_id, _arg_iv, _arg_result_id) };
}
extern "C" fn _forwarder__MuIRBuilder__new_newattr(
......
......@@ -843,7 +843,7 @@ pub struct CMuIRBuilder {
pub new_exitthread:
extern "C" fn(*mut CMuIRBuilder, CMuID, CMuVarNode, CMuExcClause),
pub new_yield: extern "C" fn(*mut CMuIRBuilder, CMuID, CMuExcClause),
pub new_newfutex: extern "C" fn(*mut CMuIRBuilder, CMuID, CMuID),
pub new_newfutex: extern "C" fn(*mut CMuIRBuilder, CMuID, CMuVarNode, CMuID),
pub new_newattr: extern "C" fn(*mut CMuIRBuilder, CMuID, CMuID),
pub new_setattr: extern "C" fn(
*mut CMuIRBuilder,
......
......@@ -611,6 +611,7 @@ pub enum NodeInst {
},
NodeNewFutex {
id: MuID,
init_val: MuVarNode,
result_id: MuID
},
NodeNewAttr {
......
......@@ -1571,9 +1571,9 @@ impl MuIRBuilder {
self.add_inst(id, NodeInst::NodeYield { id, exc_clause });
}
pub fn new_newfutex(&mut self, id: MuID, result_id: MuID) {
pub fn new_newfutex(&mut self, id: MuID, init_val: MuVarNode, result_id: MuID) {
trace!("new_newfutex");
self.add_inst(id, NodeInst::NodeNewFutex { id, result_id });
self.add_inst(id, NodeInst::NodeNewFutex { id, init_val, result_id });
}
pub fn new_newattr(&mut self, id: MuID, result_id: MuID) {
......@@ -3024,6 +3024,7 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
}
fn get_treenode(&self, fcb: &FuncCtxBuilder, id: MuID) -> P<TreeNode> {
trace!("get_treenode({:#?})", id);
if let Some(tn) = fcb.tree_nodes.get(&id) {
tn.clone()
} else if let Some(v) = self.built_constants.get(&id) {
......@@ -4645,15 +4646,16 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
unimplemented!();
}
NodeInst::NodeNewFutex { id, result_id } => {
NodeInst::NodeNewFutex { id, init_val, result_id } => {
let iv = self.get_treenode(fcb, init_val);
let futexref_t = self.ensure_futexref();
let rv = self.new_ssa(fcb, result_id, futexref_t).clone_value();
Instruction {
hdr,
value: Some(vec![rv]),
ops: vec![],
v: Instruction_::NewFutex
ops: vec![iv],
v: Instruction_::NewFutex(0)
}
}
......@@ -5685,15 +5687,16 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
&& keepalives.is_none()
);
assert!(args.len() == 1);
assert_eq!(args.len(), 2);
let impl_f = self.get_treenode(fcb, args[0]);
let impl_cnt = self.get_treenode(fcb, args[1]);
Instruction {
hdr: hdr,
value: None,
ops: vec![impl_f],
v: Instruction_::UnlockFutex(0)
ops: vec![impl_f, impl_cnt],
v: Instruction_::UnlockFutex(0, 1)
}
}
_ => unimplemented!()
......
......@@ -843,14 +843,14 @@ macro_rules! inst {
};
// NEWFUTEX
(($vm: expr, $fv: ident) $name: ident: $res: ident = NEWFUTEX)
(($vm: expr, $fv: ident) $name: ident: $res: ident = NEWFUTEX $iv: ident)
=> {
let $name = $fv.new_inst(
Instruction {
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: Some(vec![$res.clone_value()]),
ops: vec![],
v: Instruction_::NewFutex
ops: vec![$iv.clone()],
v: Instruction_::NewFutex(0)
}
);
};
......@@ -881,14 +881,14 @@ macro_rules! inst {
);
};
// UNLOCKFUTEX
(($vm: expr, $fv: ident) $name: ident: UNLOCKFUTEX $fref: ident)
(($vm: expr, $fv: ident) $name: ident: UNLOCKFUTEX $fref: ident, $cnt: ident)
=> {
let $name = $fv.new_inst(
Instruction {
hdr: MuEntityHeader::unnamed($vm.next_id()),
value: None,
ops: vec![$fref.clone()],
v: Instruction_::UnlockFutex(0)
ops: vec![$fref.clone(), $cnt.clone()],
v: Instruction_::UnlockFutex(0, 1)
}
);
};
......
......@@ -18,7 +18,10 @@ from rpython.rlib.rrtmu import rtzebu as rrtmu
from rpython.translator.platform import platform
from rpython.tool.ansi_print import AnsiLogger
from util import fncptr_from_rpy_func, fncptr_from_py_script, may_spawn_proc, bin_dir, executable_from_rpy_func
import ctypes, py, stat, os
import ctypes
import py
import stat
import os
import pytest
import time
......@@ -183,7 +186,7 @@ logger = AnsiLogger('rt_rpython_tests')
# import os
#
# start = time.time()
# os.system('sudo LD_LIBRARY_PATH=$PWD/emit %s' % exec_path)
# os.system('sudo LD_LIBRARY_PATH=$PWD/emit:$LD_LIBRARY_PATH %s' % exec_path)
# end = time.time()
#
# print("Test took: ")
......@@ -191,7 +194,7 @@ logger = AnsiLogger('rt_rpython_tests')
#
# logger.info('second call')
#
# assert True
# assert False
# @may_spawn_proc
# def test_thread_global_args():
......@@ -287,11 +290,50 @@ logger = AnsiLogger('rt_rpython_tests')
# assert 0 <= res <= 50
# @may_spawn_proc
# def test_alloc_type():
# from rpython.dev.dev_alloc_type import test_alloc_type
# fn, _ = fncptr_from_rpy_func(test_alloc_type, [], rffi.SIGNED)
#
# assert fn() == 5
# @may_spawn_proc
# def test_alloc_type():
# from rpython.dev.dev_alloc_type import test_alloc_type
# logger.info('going to build the test function')
# exec_path = executable_from_rpy_func(test_alloc_type, [], rffi.SIGNED)
#
# logger.info('going to run the test function')
#
# # import subprocess
# # subprocess.call([fn()])
# # subprocess.check_output([fn()])
#
# import subprocess
# import os, sys
#
# start = time.time()
#