WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit 8cb84785 authored by John Zhang's avatar John Zhang
Browse files

add cb_finish() to clean up callback

parent 2c0ea534
......@@ -22,3 +22,4 @@ extern void* cb_init(const char* param_s); // use void* to hide implementati
extern void cb_begin(void* cb); // data is implementation defined
extern void cb_end(void* cb);
extern void cb_report(void* cb);
extern void cb_finish(void* cb);
\ No newline at end of file
......@@ -104,3 +104,5 @@ void cb_report(void *p) {
printf(fmtstr, get_elapsed_time(&cb->t0, &cb->t1));
printf("\n");
}
void cb_finish(void *p) { free(p); }
......@@ -69,30 +69,31 @@ void* cb_init(const char* events) {
ret = pfm_initialize();
if (ret != PFM_SUCCESS)
errx(1, "Cannot initialize library: %s", pfm_strerror(ret));
ret = perf_setup_list_events(events, &cb->perfevent_fds, &cb->perfevent_num_fds);
if (ret || !cb->perfevent_num_fds)
errx(1, "cannot setup events");
cb->perfevent_fds[0].fd = -1;
for(i=0; i < cb->perfevent_num_fds; i++) {
/* request timing information necessary for scaling */
cb->perfevent_fds[i].hw.read_format = PERF_FORMAT_SCALE;
cb->perfevent_fds[i].hw.disabled = (i == 0); /* do not start now */
cb->perfevent_fds[i].hw.inherit = 1; /* pass on to child threads */
/* each event is in an independent group (multiplexing likely) */
cb->perfevent_fds[i].fd = perf_event_open(&cb->perfevent_fds[i].hw, 0, -1, cb->perfevent_fds[0].fd, 0);
if (cb->perfevent_fds[i].fd == -1)
err(1, "cannot open event %d", i);
}
return (void*)cb;
}
void cb_begin(void* p) {
Callback *cb = (Callback*)p;
int ret;
// start counting now
ret = ioctl(cb->perfevent_fds[0].fd, PERF_EVENT_IOC_ENABLE, 0);
if (ret)
......@@ -102,7 +103,7 @@ void cb_begin(void* p) {
void cb_end(void* p) {
Callback *cb = (Callback*)p;
int ret;
// stop counting now
ret = ioctl(cb->perfevent_fds[0].fd, PERF_EVENT_IOC_DISABLE, 0);
if (ret)
......@@ -156,7 +157,7 @@ void perfevent_read(Callback* cb) {
void cb_report(void* p) {
Callback *cb = (Callback*)p;
perfevent_read(cb);
// reset
int i, ret;
for(i=0; i < perfevent_num_fds; i++) {
......
......@@ -35,3 +35,5 @@ void cb_end(void* cb) {
void cb_report(void* cb) {
printf("report.\n");
}
void cb_finish(void* cb) { }
\ No newline at end of file
......@@ -26,14 +26,17 @@ void mubench_init_callback_symbols(MuIRBuilder *bldr)
sig_cb_begin = bldr->gen_sym(bldr, "@mubench.sig_cb_begin");
sig_cb_end = bldr->gen_sym(bldr, "@mubench.sig_cb_end");
sig_cb_report = bldr->gen_sym(bldr, "@mubench.sig_cb_report");
sig_cb_finish = bldr->gen_sym(bldr, "@mubench.sig_cb_finish");
t_fp_cb_init = bldr->gen_sym(bldr, "@mubench.t_fp_cb_init");
t_fp_cb_begin = bldr->gen_sym(bldr, "@mubench.t_fp_cb_begin");
t_fp_cb_end = bldr->gen_sym(bldr, "@mubench.t_fp_cb_end");
t_fp_cb_report = bldr->gen_sym(bldr, "@mubench.t_fp_cb_report");
t_fp_cb_finish = bldr->gen_sym(bldr, "@mubench.t_fp_cb_finish");
extern_cb_init = bldr->gen_sym(bldr, "@mubench.extern_cb_init");
extern_cb_begin = bldr->gen_sym(bldr, "@mubench.extern_cb_begin");
extern_cb_end = bldr->gen_sym(bldr, "@mubench.extern_cb_end");
extern_cb_report = bldr->gen_sym(bldr, "@mubench.extern_cb_report");
extern_cb_finish = bldr->gen_sym(bldr, "@mubench.extern_cb_finish");
t_cchar = bldr->gen_sym(bldr, "@mubench.t_cchar");
t_cchara = bldr->gen_sym(bldr, "@mubench.t_cchara");
t_ccharp = bldr->gen_sym(bldr, "@mubench.t_ccharp");
......@@ -50,14 +53,18 @@ void mubench_init_callback_symbols(MuIRBuilder *bldr)
(MuTypeNode[1]){t_callback_p}, 1, NULL, 0);
bldr->new_funcsig(bldr, sig_cb_report,
(MuTypeNode[1]){t_callback_p}, 1, NULL, 0);
bldr->new_funcsig(bldr, sig_cb_finish,
(MuTypeNode[1]){t_callback_p}, 1, NULL, 0);
bldr->new_type_ufuncptr(bldr, t_fp_cb_init, sig_cb_init);
bldr->new_type_ufuncptr(bldr, t_fp_cb_begin, sig_cb_begin);
bldr->new_type_ufuncptr(bldr, t_fp_cb_end, sig_cb_end);
bldr->new_type_ufuncptr(bldr, t_fp_cb_report, sig_cb_report);
bldr->new_type_ufuncptr(bldr, t_fp_cb_finish, sig_cb_finish);
bldr->new_const_extern(bldr, extern_cb_init, t_fp_cb_init, "cb_init");
bldr->new_const_extern(bldr, extern_cb_begin, t_fp_cb_begin, "cb_begin");
bldr->new_const_extern(bldr, extern_cb_end, t_fp_cb_end, "cb_end");
bldr->new_const_extern(bldr, extern_cb_report, t_fp_cb_report, "cb_report");
bldr->new_const_extern(bldr, extern_cb_finish, t_fp_cb_finish, "cb_finish");
bldr->new_type_int(bldr, t_cchar, 8);
bldr->new_type_hybrid(bldr, t_cchara, NULL, 0, t_cchar);
bldr->new_type_uptr(bldr, t_ccharp, t_cchara);
......
......@@ -40,14 +40,17 @@ The interface consists of the following definitions:
.funcsig @mubench.sig_cb_begin = (@mubench.t_callback_p) -> ()
.funcsig @mubench.sig_cb_end = (@mubench.t_callback_p) -> ()
.funcsig @mubench.sig_cb_report = (@mubench.t_callback_p) -> ()
.funcsig @mubench.sig_cb_finish = (@mubench.t_callback_p) -> ()
.type @mubench.t_fp_cb_init = ufuncptr<@mubench.sig_cb_init>
.type @mubench.t_fp_cb_begin = ufuncptr<@mubench.sig_cb_begin>
.type @mubench.t_fp_cb_end = ufuncptr<@mubench.sig_cb_end>
.type @mubench.t_fp_cb_report = ufuncptr<@mubench.sig_cb_report>
.type @mubench.t_fp_cb_finish = ufuncptr<@mubench.sig_cb_finish>
.const @mubench.extern_cb_init <@mubench.t_fp_cb_init> = EXTERN "cb_init"
.const @mubench.extern_cb_begin <@mubench.t_fp_cb_begin> = EXTERN "cb_begin"
.const @mubench.extern_cb_end <@mubench.t_fp_cb_end> = EXTERN "cb_end"
.const @mubench.extern_cb_report <@mubench.t_fp_cb_report> = EXTERN "cb_report"
.const @mubench.extern_cb_finish <@mubench.t_fp_cb_finish> = EXTERN "cb_finish"
*/
MuID t_void;
......@@ -56,14 +59,17 @@ MuID sig_cb_init;
MuID sig_cb_begin;
MuID sig_cb_end;
MuID sig_cb_report;
MuID sig_cb_finish;
MuID t_fp_cb_init;
MuID t_fp_cb_begin;
MuID t_fp_cb_end;
MuID t_fp_cb_report;
MuID t_fp_cb_finish;
MuID extern_cb_init;
MuID extern_cb_begin;
MuID extern_cb_end;
MuID extern_cb_report;
MuID extern_cb_finish;
MuID t_cchar;
MuID t_cchara;
MuID t_ccharp;
......
......@@ -98,14 +98,17 @@ int main(int argc, char **argv)
sig_cb_begin,
sig_cb_end,
sig_cb_report,
sig_cb_finish,
t_fp_cb_init,
t_fp_cb_begin,
t_fp_cb_end,
t_fp_cb_report,
t_fp_cb_finish,
extern_cb_init,
extern_cb_begin,
extern_cb_end,
extern_cb_report,
extern_cb_finish,
t_cchar,
t_cchara,
t_ccharp
......
......@@ -30,6 +30,7 @@ def get_callback(libcb_path):
c_cb_begin = external("cb_begin", [ctypes.c_void_p], None)
c_cb_end = external("cb_end", [ctypes.c_void_p], None)
c_cb_report = external("cb_report", [ctypes.c_void_p], None)
c_cb_finish = external("cb_finish", [ctypes.c_void_p], None)
class Callback:
def __init__(self, param_s):
......@@ -44,4 +45,7 @@ def get_callback(libcb_path):
def report(self):
c_cb_report(self.cb)
def finish(self):
c_cb_finish(self.cb)
return Callback
......@@ -35,6 +35,7 @@ def get_callback(libcb_path):
c_cb_begin = external("cb_begin", [rffi.VOIDP], rffi.lltype.Void)
c_cb_end = external("cb_end", [rffi.VOIDP], rffi.lltype.Void)
c_cb_report = external("cb_report", [rffi.VOIDP], rffi.lltype.Void)
c_cb_finish = external("cb_report", [rffi.VOIDP], rffi.lltype.Void)
class Callback:
def __init__(self, param_s):
......@@ -50,4 +51,7 @@ def get_callback(libcb_path):
def report(self):
c_cb_report(self.cb)
def finish(self):
c_cb_finish(self.cb)
return Callback
\ No newline at end of file
......@@ -87,7 +87,8 @@ limitations under the License.
%blk3(<@t_i32> %sum <@t_i32> %n <@t_i32> %scale_factor <@mubench.t_callback_p> %cb):
CCALL <@mubench.t_fp_cb_end @mubench.sig_cb_end> @mubench.extern_cb_end (%cb)
CALL <@mubench.sig_cb_report> @mubench.cb_report (%cb)
CCALL <@mubench.t_fp_cb_report @mubench.sig_cb_report> @mubench.extern_cb_report (%cb)
CCALL <@mubench.t_fp_cb_finish @mubench.sig_cb_finish> @mubench.extern_cb_finish (%cb)
%fib_n = CALL <@sig_fib> @fib (%n)
%expected = MUL <@t_i32> %fib_n %scale_factor
%cmpres = NE <@t_i32> %sum %expected
......@@ -418,7 +419,7 @@ void build_func_entry(MuIRBuilder *b)
{ // blk3
MuID sum, n, scale_factor, cb, fib_n, expected, cmpres, retcode;
MuID ops[8];
MuID ops[9];
sum = b->gen_sym(b, "@entry.v1.blk3.sum");
n = b->gen_sym(b, "@entry.v1.blk3.n");
scale_factor = b->gen_sym(b, "@entry.v1.blk3.scale_factor");
......@@ -427,7 +428,7 @@ void build_func_entry(MuIRBuilder *b)
expected = b->gen_sym(b, "@entry.v1.blk3.expected");
cmpres = b->gen_sym(b, "@entry.v1.blk3.cmpres");
retcode = b->gen_sym(b, "@entry.v1.blk3.retcode");
for (int i = 0; i < 8; i ++)
for (int i = 0; i < 9; i ++)
ops[i] = b->gen_sym(b, NULL);
b->new_ccall(b, ops[0], NULL, 0, MU_CC_DEFAULT,
......@@ -436,19 +437,22 @@ void build_func_entry(MuIRBuilder *b)
b->new_ccall(b, ops[1], NULL, 0, MU_CC_DEFAULT,
t_fp_cb_report, sig_cb_report, extern_cb_report,
IDARR(1, cb), 1, MU_NO_ID, MU_NO_ID);
b->new_call(b, ops[2], IDARR(1, fib_n), 1, sig_fib, fib,
b->new_ccall(b, ops[2], NULL, 0, MU_CC_DEFAULT,
t_fp_cb_finish, sig_cb_finish, extern_cb_finish,
IDARR(1, cb), 1, MU_NO_ID, MU_NO_ID);
b->new_call(b, ops[3], IDARR(1, fib_n), 1, sig_fib, fib,
IDARR(1, n), 1, MU_NO_ID, MU_NO_ID);
b->new_binop(b, ops[3], expected, MU_BINOP_MUL, t_i32, fib_n, scale_factor, MU_NO_ID);
b->new_cmp(b, ops[4], cmpres, MU_CMP_NE, t_i32, sum, expected);
b->new_conv(b, ops[5], retcode, MU_CONV_ZEXT, t_i1, t_i32, cmpres);
b->new_binop(b, ops[4], expected, MU_BINOP_MUL, t_i32, fib_n, scale_factor, MU_NO_ID);
b->new_cmp(b, ops[5], cmpres, MU_CMP_NE, t_i32, sum, expected);
b->new_conv(b, ops[6], retcode, MU_CONV_ZEXT, t_i1, t_i32, cmpres);
b->new_ccall(b, ops[6], NULL, 0, MU_CC_DEFAULT, t_fp_exit, sig_exit, extern_exit,
b->new_ccall(b, ops[7], NULL, 0, MU_CC_DEFAULT, t_fp_exit, sig_exit, extern_exit,
IDARR(1, retcode), 1, MU_NO_ID, MU_NO_ID);
b->new_ret(b, ops[7], IDARR(1, c_0), 1);
b->new_ret(b, ops[8], IDARR(1, c_0), 1);
b->new_bb(b, blk3,
IDARR(4, sum, n, scale_factor, cb),
IDARR(4, t_i32, t_i32, t_i32, t_callback_p), 4,
MU_NO_ID, ops, 8);
MU_NO_ID, ops, 9);
}
b->new_func(b, entry, sig_main);
b->new_func_ver(b, v1, entry, IDARR(4, blk0, blk1, blk2, blk3), 4);
......
......@@ -45,5 +45,6 @@ int main(int argc, char** argv) {
cb_end(cb);
printf("sum = %d\n", sum);
cb_report(cb);
cb_finish(cb);
return 0;
}
\ No newline at end of file
......@@ -33,6 +33,7 @@ def main(argv):
s += fib(n)
cb.end()
cb.report()
cb.finish()
return s != fib(n) * scale_factor
......
......@@ -41,6 +41,7 @@ def target(driver, args):
s += fib(n)
cb.end()
cb.report()
cb.finish()
return int(s != fib(n) * scale_factor)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment