[llvm-commits] CVS: reopt/lib/LightWtProfiling/scheduler.cpp scheduler.h Timer.cpp Timer.h
Brian Gaeke
gaeke at cs.uiuc.edu
Tue Jan 13 12:17:02 PST 2004
Changes in directory reopt/lib/LightWtProfiling:
scheduler.cpp updated: 1.4 -> 1.5
scheduler.h updated: 1.2 -> 1.3
Timer.cpp (r1.4) removed
Timer.h (r1.3) removed
---
Log message:
Merge the Timer and scheduler modules.
Make the priority-queue code less verbose.
---
Diffs of the changes: (+96 -60)
Index: reopt/lib/LightWtProfiling/scheduler.cpp
diff -u reopt/lib/LightWtProfiling/scheduler.cpp:1.4 reopt/lib/LightWtProfiling/scheduler.cpp:1.5
--- reopt/lib/LightWtProfiling/scheduler.cpp:1.4 Wed Nov 19 16:51:49 2003
+++ reopt/lib/LightWtProfiling/scheduler.cpp Tue Jan 13 12:16:32 2004
@@ -1,91 +1,121 @@
+// Implements an interval timer used for removing instrumentation in
+// response to phase-change detection.
+
#include "Globals.h"
-#include "Timer.h"
-#include "reopt/VirtualMem.h"
+//#include "scheduler.h"
+//#include "reopt/VirtualMem.h"
#include "reopt/InstrUtils.h"
#include <queue>
+#include <csignal>
namespace llvm {
-class priority_queue_entry
-{
-public:
- priority_queue_entry(uint64_t time, uint64_t where) :
- cycle_to_process(time),
- addr(where) {}
- uint64_t cycle_to_process;
- uint64_t addr;
-};
-
-bool operator<=(priority_queue_entry p1, priority_queue_entry p2)
-{
- return p1.cycle_to_process <= p2.cycle_to_process;
-}
-
-bool operator>=(priority_queue_entry p1, priority_queue_entry p2)
-{
- return operator<=(p2,p1);
-}
-
-
-bool operator>(priority_queue_entry p1, priority_queue_entry p2)
-{
- return !operator<=(p1, p2);
-}
-
-bool operator<(priority_queue_entry p1, priority_queue_entry p2)
-{
- return !operator>=(p1, p2);
-}
-
-bool operator==(priority_queue_entry p1, priority_queue_entry p2)
-{
- return p1.cycle_to_process == p2.cycle_to_process;
-}
-
-bool operator!=(priority_queue_entry p1, priority_queue_entry p2)
-{
- return !(operator==(p1, p2));
-}
-
-class my_compare
-{
+// A qentry (queue entry) is a (cycle, addr) tuple.
+class qentry {
public:
- bool operator()(priority_queue_entry p1, priority_queue_entry p2)
- {
- return p1>p2;
- }
+ qentry (uint64_t _cycle, uint64_t _addr) : cycle (_cycle), addr (_addr) { }
+ uint64_t cycle;
+ uint64_t addr;
};
+// Comparators and comparator function object for qentries.
+bool operator<= (qentry p1, qentry p2) { return p1.cycle <= p2.cycle; }
+bool operator>= (qentry p1, qentry p2) { return operator<= (p2, p1); }
+bool operator> (qentry p1, qentry p2) { return !operator<= (p1, p2); }
+bool operator< (qentry p1, qentry p2) { return !operator>= (p1, p2); }
+bool operator== (qentry p1, qentry p2) { return p1.cycle == p2.cycle; }
+bool operator!= (qentry p1, qentry p2) { return !operator== (p1, p2); }
+struct qcompare { bool operator() (qentry p1, qentry p2) { return p1 > p2; } };
+// Priority queue of qentries sorted by cycle.
+std::priority_queue<qentry, std::vector<qentry>, qcompare> pqueue;
-std::priority_queue<priority_queue_entry, std::vector<priority_queue_entry>,
- my_compare> pqueue;
extern "C" void llvm_first_trigger ();
+extern "C" void do_timer_interval ();
+uint64_t llvm_interval_counter;
+static sigset_t sig_usr2;
+static sigset_t sig_old;
+static sigset_t sig_all;
/// Examine the queue, processing and removing entries for which
-/// cycle_to_process <= llvm_interval_counter. We process entries by
+/// cycle <= llvm_interval_counter. We process entries by
/// inserting a call to llvm_first_trigger() at addr.
///
extern "C" void do_timer_interval () {
- while(!pqueue.empty ()
- && pqueue.top ().cycle_to_process <= llvm_interval_counter) {
+ while(!pqueue.empty () && pqueue.top ().cycle <= llvm_interval_counter) {
uint64_t addr = pqueue.top ().addr;
// Insert a call at ADDR to llvm_first_trigger.
vm->writeInstToVM (addr,
- getCallInstr ((uint64_t)&llvm_first_trigger, addr));
+ getCallInstr ((uint64_t)&llvm_first_trigger, addr));
doFlush (addr-16, addr+16);
pqueue.pop ();
}
}
+void mask_interrupt () {
+ sigprocmask (SIG_BLOCK, &sig_usr2, &sig_old);
+}
+
+void unmask_interrupt () {
+ sigprocmask (SIG_UNBLOCK, &sig_usr2, NULL);
+}
+
+void mask_all_interrupt () {
+ sigprocmask (SIG_BLOCK, &sig_all, &sig_old);
+}
+
+void unmask_all_interrupt () {
+ sigprocmask (SIG_UNBLOCK, &sig_all, NULL);
+}
+
/// Insert a new pair <TIME,ADDR> into the priority queue (with
/// interrupts masked, though these *_interrupt fns don't do anything
/// at the moment!)
///
-int insert_address_at(uint64_t time, uint64_t addr)
-{
- mask_interrupt();
- pqueue.push(priority_queue_entry(time,addr));
- unmask_interrupt();
+int insert_address_at (uint64_t time, uint64_t addr) {
+ mask_interrupt ();
+ pqueue.push (qentry (time,addr));
+ unmask_interrupt ();
return 0;
+}
+
+/// Signal handler for SIGUSR2.
+/// FIXME: Should use auto-blocking BSD signals
+///
+void timer_handler (int i) {
+ mask_all_interrupt ();
+ signal (SIGUSR2, SIG_IGN);
+ llvm_interval_counter++;
+ do_timer_interval ();
+ signal (SIGUSR2, &timer_handler);
+ unmask_all_interrupt ();
+}
+
+/// Set up the phase-change detection timer. Returns true if there is
+/// an error; false otherwise.
+///
+bool initialize_timer () {
+ // Allocate and initialize the real-time interval timer.
+ struct sigevent timer_evp;
+ memset (&timer_evp, 0, sizeof (timer_evp));
+ timer_evp.sigev_signo = SIGUSR2;
+ timer_evp.sigev_notify = SIGEV_SIGNAL;
+ timer_t timer_id;
+ if (timer_create (CLOCK_REALTIME, &timer_evp, &timer_id) < 0) {
+ std::cerr << "Error creating timer: " << strerror (errno) << "\n";
+ return true;
+ }
+ struct itimerspec timer_spec, old_timer_spec;
+ timer_spec.it_value.tv_sec = timer_interval_sec;
+ timer_spec.it_value.tv_nsec = timer_interval_nsec;
+ timer_spec.it_interval.tv_sec = 1;
+ timer_spec.it_interval.tv_nsec = 0;
+ if (timer_settime (timer_id, 0, &timer_spec, &old_timer_spec) < 0) {
+ std::cerr << "Error initializing timer: " << strerror (errno) << "\n";
+ return true;
+ }
+
+ // Set up signal handler for SIGUSR2.
+ signal (SIGUSR2, &timer_handler);
+ return false;
}
} // end namespace llvm
Index: reopt/lib/LightWtProfiling/scheduler.h
diff -u reopt/lib/LightWtProfiling/scheduler.h:1.2 reopt/lib/LightWtProfiling/scheduler.h:1.3
--- reopt/lib/LightWtProfiling/scheduler.h:1.2 Wed Jan 7 16:37:55 2004
+++ reopt/lib/LightWtProfiling/scheduler.h Tue Jan 13 12:16:32 2004
@@ -7,6 +7,12 @@
int insert_address_at(uint64_t time, uint64_t addr);
+void mask_interrupt ();
+void unmask_interrupt ();
+bool initialize_timer ();
+
+extern uint64_t llvm_interval_counter;
+
}; // end namespace llvm
#endif // SCHEDULER_H
More information about the llvm-commits
mailing list