//------------------------------------------------- // add_scheduling_quantum - add a scheduling // quantum; the smallest active one is the one // that is in use //------------------------------------------------- void add_scheduling_quantum(attotime quantum, attotime duration) { assert(quantum.seconds() == 0); attotime curtime = time(); attotime expire = curtime + duration; attoseconds_t quantum_attos = quantum.attoseconds(); // figure out where to insert ourselves, expiring any quanta that are out-of-date quantum_slot insert_after = null; quantum_slot next; for (quantum_slot quant = m_quantum_list.first(); quant != null; quant = next) { // if this quantum is expired, nuke it next = quant.next(); if (curtime >= quant.expire()) { m_quantum_allocator.reclaim(m_quantum_list.detach(quant)); } // if this quantum is shorter than us, we need to be inserted afterwards else if (quant.requested() <= quantum_attos) { insert_after = quant; } } // if we found an exact match, just take the maximum expiry time if (insert_after != null && insert_after.requested() == quantum_attos) { insert_after.expire_set(attotime.Max(insert_after.expire(), expire)); } // otherwise, allocate a new quantum and insert it after the one we picked else { quantum_slot quant = m_quantum_allocator.alloc(); quant.requested_set(quantum_attos); quant.actual_set(Math.Max(quantum_attos, m_quantum_minimum)); quant.expire_set(expire); m_quantum_list.insert_after(quant, insert_after); } }
// scheduling helpers //------------------------------------------------- // compute_perfect_interleave - compute the // "perfect" interleave interval //------------------------------------------------- public void compute_perfect_interleave() { // ensure we have a list of executing devices if (m_execute_list == null) { rebuild_execute_list(); } // start with the first one device_execute_interface first = m_execute_list; if (first != null) { // start with a huge time factor and find the 2nd smallest cycle time attoseconds_t smallest = first.minimum_quantum(); attoseconds_t perfect = attotime.ATTOSECONDS_PER_SECOND - 1; for (device_execute_interface exec = first.nextexec; exec != null; exec = exec.nextexec) { // find the 2nd smallest cycle interval attoseconds_t curquantum = exec.minimum_quantum(); if (curquantum < smallest) { perfect = smallest; smallest = curquantum; } else if (curquantum < perfect) { perfect = curquantum; } } // if this is a new minimum quantum, apply it if (m_quantum_minimum != perfect) { // adjust all the actuals; this doesn't affect the current m_quantum_minimum = perfect; for (quantum_slot quant = m_quantum_list.first(); quant != null; quant = quant.next()) { quant.actual_set(Math.Max(quant.requested(), m_quantum_minimum)); } } } }