diff --git a/README.md b/README.md index 938c038..fbe9625 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,7 @@ mbed test -m DISCO_H747I -t GCC_ARM -n advdembsof_library-tests-sensors-hdc1000 # Some questions ## If you print CPU statistics at the end of every major cycle (in the super-loop), what CPU usage do you observe? How can you explain the observed CPU uptime? -We observe a 100% usage because on each CPU cycle it compare if time is done. \ No newline at end of file +We observe a 100% usage because on each CPU cycle it compare if time is done. + +## If you run the program after the change from busy wait to sleep calls, what CPU usage do you observe? How can you explain the observed CPU uptime? +We can observe only a usage of 75% because the CPU is more on Idle with Thread sleep. \ No newline at end of file diff --git a/static_scheduling/bike_system.cpp b/static_scheduling/bike_system.cpp index 8bdb6ea..02b31ad 100644 --- a/static_scheduling/bike_system.cpp +++ b/static_scheduling/bike_system.cpp @@ -174,12 +174,18 @@ void BikeSystem::temperatureTask() { tr_warn("Tick2 %" PRIu64, _timer.elapsed_time().count()); + ThisThread::sleep_for( + std::chrono::duration_cast( + kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime) + ) + ); + // simulate task computation by waiting for the required task computation time - std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero(); - while (elapsedTime < kTemperatureTaskComputationTime) { - elapsedTime = _timer.elapsed_time() - taskStartTime; - } +// std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero(); +// while (elapsedTime < kTemperatureTaskComputationTime) { +// elapsedTime = _timer.elapsed_time() - taskStartTime; +// } _taskLogger.logPeriodAndExecutionTime( _timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime); @@ -206,12 +212,18 @@ void BikeSystem::displayTask1() { _displayDevice.displaySpeed(_currentSpeed); _displayDevice.displayDistance(_traveledDistance); + ThisThread::sleep_for( + std::chrono::duration_cast( + kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime) + ) + ); + // simulate task computation by waiting for the required task computation time - std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero(); - while (elapsedTime < kDisplayTask1ComputationTime) { - elapsedTime = _timer.elapsed_time() - taskStartTime; - } +// std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero(); +// while (elapsedTime < kDisplayTask1ComputationTime) { +// elapsedTime = _timer.elapsed_time() - taskStartTime; +// } _taskLogger.logPeriodAndExecutionTime( _timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime); @@ -222,12 +234,18 @@ void BikeSystem::displayTask2() { _displayDevice.displayTemperature(_currentTemperature); + ThisThread::sleep_for( + std::chrono::duration_cast( + kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime) + ) + ); + // simulate task computation by waiting for the required task computation time - std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero(); - while (elapsedTime < kDisplayTask2ComputationTime) { - elapsedTime = _timer.elapsed_time() - taskStartTime; - } +// std::chrono::microseconds elapsedTime = std::chrono::microseconds::zero(); +// while (elapsedTime < kDisplayTask2ComputationTime) { +// elapsedTime = _timer.elapsed_time() - taskStartTime; +// } _taskLogger.logPeriodAndExecutionTime( _timer, advembsof::TaskLogger::kDisplayTask2Index, taskStartTime); }