ll_define_primitive_end /* ** Compile into code to generate a value for an exports vector. */ ll_define_primitive(pair, _ir_compile2_export, _2(self, ir), _0()) { ll_v x = ll_SELF; ll_v var = ll_car(x); ll_v type = var_type(x); ll_v index = var_index(x); ll_assert_ref(IR); /* slot ref */ if ( ll_EQ(type, ll_s(slot)) ) { /* Create a const containing the global var name */ index = ll_call(ll_o(_ir_const_index), _2(IR, var)); } else if ( ll_EQ(type, ll_s(glo)) ) { ll_abort("<pair>:%ir-compile2-export"); } /* undef export is a local from a car-pos sub lambda */ if ( ll_EQ(type, ll_undef) ) { ll_call_tail(ll_o(_ir_compile2), _3(ll_undef, IR, ll_f)); } else { ll_v emit_type = type; /* env_loc is an environment slot containing a locative */ if ( ll_EQ(type, ll_s(env_loc)) ) { emit_type = ll_s(env); } if ( ll_unbox_boolean(index) ) { ll_call(ll_o(_ir_emit_with_int), _3(IR, emit_type, index)); } else { ll_call(ll_o(_ir_emit), _2(IR, emit_type)); } /* ** arg and local values are stored directly into the exports vector. ** so put the value, not a locative to the arg or local in the exports vector. */ if ( ll_EQ(type, ll_s(arg)) || ll_EQ(type, ll_s(local)) || ll_EQ(type, ll_s(env_loc)) ) { ll_call_tail(ll_o(_ir_emit), _2(IR, ll_s(contents))); } } }
vec3 obox::center() const { vec3 _1(x1y2z1 + (x2y1z2 - x1y2z1) / 2.0f); vec3 _2(x2y2z1 + (x1y1z2 - x2y2z1) / 2.0f); vec3 _3(x2y1z1 + (x1y2z2 - x2y1z1) / 2.0f); return vec3((_1 + _2 + _3) / 3.0f); }
ll_define_primitive_end ll_define_primitive(object, eval_no_const_fold, __1(obj, env), _0()) { ll_v obj; ll_v env; ll_v expr; ll_v ir; ll_v op; obj = ll_SELF; env = ll_ARGV[1]; expr = ll_call(ll_o(eval_stage_1), _2(obj, env)); ir = ll_call(ll_o(eval_stage_2), _2(expr, env)); /* Disable constant folding */ ll_call(ll_o(set_propertyE), _3(ir, ll_s(no_const_folding), ll_t)); ir = ll_call(ll_o(eval_stage_3), _2(ir, env)); op = ll_call(ll_o(_ir_operation), _1(ir)); ll_call_tail(op, _0()); }
ll_define_primitive_end ll_define_primitive(object, eval_stage_4, __1(obj, env), _0()) { ll_v ir; ir = ll_SELF; /**********************************************************************/ /* Begin emiting code */ ll_call(ll_o(_ir_compile2_body), _3(ir, ir, ll_t)); ll_return(ir); }
void do_scheduling_analysis(bigtime_t startTime, bigtime_t endTime, size_t bufferSize) { printf("\n"); // allocate a chunk of memory for the scheduling analysis void* buffer = malloc(bufferSize); if (buffer == NULL) { fprintf(stderr, "Error: Failed to allocate memory for the scheduling " "analysis.\n"); exit(1); } MemoryDeleter _(buffer); // do the scheduling analysis scheduling_analysis analysis; status_t error = _kern_analyze_scheduling(startTime, endTime, buffer, bufferSize, &analysis); if (error != B_OK) { fprintf(stderr, "Error: Scheduling analysis failed: %s\n", strerror(error)); exit(1); } // allocate arrays for grouping and sorting the wait objects scheduling_analysis_thread_wait_object** waitObjects = new(std::nothrow) scheduling_analysis_thread_wait_object*[ analysis.thread_wait_object_count]; ArrayDeleter<scheduling_analysis_thread_wait_object*> _2(waitObjects); wait_object_group* waitObjectGroups = new(std::nothrow) wait_object_group[ analysis.thread_wait_object_count]; ArrayDeleter<wait_object_group> _3(waitObjectGroups); if (waitObjects == NULL || waitObjectGroups == NULL) { fprintf(stderr, "Error: Out of memory\n"); exit(1); } printf("scheduling analysis: %lu threads, %llu wait objects, " "%llu thread wait objects\n", analysis.thread_count, analysis.wait_object_count, analysis.thread_wait_object_count); // sort the thread by run time std::sort(analysis.threads, analysis.threads + analysis.thread_count, ThreadRunTimeComparator()); for (uint32 i = 0; i < analysis.thread_count; i++) { scheduling_analysis_thread* thread = analysis.threads[i]; // compute total wait time and prepare the objects for sorting int32 waitObjectCount = 0; bigtime_t waitTime = 0; scheduling_analysis_thread_wait_object* threadWaitObject = thread->wait_objects; while (threadWaitObject != NULL) { waitObjects[waitObjectCount++] = threadWaitObject; waitTime += threadWaitObject->wait_time; threadWaitObject = threadWaitObject->next_in_list; } // sort the wait objects by type + name std::sort(waitObjects, waitObjects + waitObjectCount, WaitObjectGroupingComparator()); // create the groups wait_object_group* group = NULL; int32 groupCount = 0; for (int32 i = 0; i < waitObjectCount; i++) { scheduling_analysis_thread_wait_object* threadWaitObject = waitObjects[i]; scheduling_analysis_wait_object* waitObject = threadWaitObject->wait_object; if (groupCount == 0 || strcmp(waitObject->name, "?") == 0 || waitObject->type != group->objects[0]->wait_object->type || strcmp(waitObject->name, group->objects[0]->wait_object->name) != 0) { // create a new group group = &waitObjectGroups[groupCount++]; group->objects = waitObjects + i; group->count = 0; group->wait_time = 0; group->waits = 0; } group->count++; group->wait_time += threadWaitObject->wait_time; group->waits += threadWaitObject->waits; } // sort the groups by wait time std::sort(waitObjectGroups, waitObjectGroups + groupCount, WaitObjectGroupTimeComparator()); printf("\nthread %ld \"%s\":\n", thread->id, thread->name); printf(" run time: %lld us (%lld runs)\n", thread->total_run_time, thread->runs); printf(" wait time: %lld us\n", waitTime); printf(" latencies: %lld us (%lld)\n", thread->total_latency, thread->latencies); printf(" preemptions: %lld us (%lld)\n", thread->total_rerun_time, thread->reruns); printf(" unspecified: %lld us\n", thread->unspecified_wait_time); printf(" waited on:\n"); for (int32 i = 0; i < groupCount; i++) { wait_object_group& group = waitObjectGroups[i]; char buffer[1024]; if (group.count == 1) { // only one element -- just print it scheduling_analysis_thread_wait_object* threadWaitObject = group.objects[0]; scheduling_analysis_wait_object* waitObject = threadWaitObject->wait_object; wait_object_to_string(waitObject, buffer); printf(" %s: %lld us (%lld)\n", buffer, threadWaitObject->wait_time, threadWaitObject->waits); } else { // sort the wait objects by wait time std::sort(group.objects, group.objects + group.count, WaitObjectTimeComparator()); // print the group line wait_object_to_string(group.objects[0]->wait_object, buffer, true); printf(" group %s: %lld us (%lld)\n", buffer, group.wait_time, group.waits); // print the wait objects for (int32 k = 0; k < group.count; k++) { scheduling_analysis_thread_wait_object* threadWaitObject = group.objects[k]; scheduling_analysis_wait_object* waitObject = threadWaitObject->wait_object; wait_object_to_string(waitObject, buffer); printf(" %s: %lld us (%lld)\n", buffer, threadWaitObject->wait_time, threadWaitObject->waits); } } } } }
// Update status_t ShareAttrDir::Update(const AttrDirInfo& dirInfo, DoublyLinkedList<ShareAttrDirIterator>* iterators) { if (!dirInfo.isValid) return B_BAD_VALUE; if (fRevision >= dirInfo.revision) return B_OK; // allocate an array for the old attributes int32 oldCount = fAttributes.Size(); Attribute** oldAttributes = new(std::nothrow) Attribute*[oldCount]; if (!oldAttributes) return B_NO_MEMORY; ArrayDeleter<Attribute*> _(oldAttributes); // get the new attributes Attribute** newAttributes = NULL; int32 newCount = 0; status_t error = _GetAttributes(dirInfo, newAttributes, newCount); if (error != B_OK) return error; ArrayDeleter<Attribute*> _2(newAttributes); // sort the iterators int32 iteratorCount = (iterators ? iterators->Count() : 0); if (iteratorCount > 0) { // allocate an array ShareAttrDirIterator** _iterators = new(std::nothrow) ShareAttrDirIterator*[iteratorCount]; if (!_iterators) return B_NO_MEMORY; ArrayDeleter<ShareAttrDirIterator*> _3(_iterators); // move the iterators for (int32 i = 0; i < iteratorCount; i++) { ShareAttrDirIterator* iterator = iterators->First(); _iterators[i] = iterator; iterators->Remove(iterator); } // sort them qsort(_iterators, iteratorCount, sizeof(ShareAttrDirIterator*), compare_iterators); // move them back into the list for (int32 i = 0; i < iteratorCount; i++) iterators->Insert(_iterators[i]); } // remove the old attributes for (int32 i = 0; i < oldCount; i++) { Attribute* attribute = fAttributes.GetFirst(); oldAttributes[i] = attribute; fAttributes.Remove(attribute); } // add the new attributes int32 oldIndex = 0; int32 newIndex = 0; ShareAttrDirIterator* iterator = (iterators ? iterators->First() : NULL); while (oldIndex < oldCount || newIndex < newCount) { Attribute* oldAttr = (oldCount > 0 ? oldAttributes[oldIndex] : NULL); Attribute* newAttr = (newCount > 0 ? newAttributes[newIndex] : NULL); int cmp = compare_attributes(oldAttr, newAttr); if (cmp < 0) { // oldAttr is obsolete: move all iterators pointing to it to the // next new attribute while (iterator && iterator->GetCurrentAttribute() == oldAttr) { iterator->SetCurrentAttribute(newAttr); iterator = iterators->GetNext(iterator); } oldIndex++; } else if (cmp > 0) { // newAttr is new fAttributes.Insert(newAttr); newIndex++; } else { // oldAttr == newAttr fAttributes.Insert(newAttr); oldIndex++; newIndex++; // move the attributes pointing to this attribute while (iterator && iterator->GetCurrentAttribute() == oldAttr) { iterator->SetCurrentAttribute(newAttr); iterator = iterators->GetNext(iterator); } } } // delete the old attributes for (int32 i = 0; i < oldCount; i++) Attribute::DeleteAttribute(oldAttributes[i]); fRevision = dirInfo.revision; fUpToDate = true; return B_OK; }