Willy Tarreau | 609aad9 | 2018-11-22 08:31:09 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * include/proto/activity.h |
| 3 | * This file contains macros and inline functions for activity measurements. |
| 4 | * |
| 5 | * Copyright (C) 2000-2018 Willy Tarreau - w@1wt.eu |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _PROTO_ACTIVITY_H |
| 23 | #define _PROTO_ACTIVITY_H |
| 24 | |
| 25 | #include <common/config.h> |
| 26 | #include <common/hathreads.h> |
| 27 | #include <common/time.h> |
| 28 | #include <types/activity.h> |
| 29 | |
| 30 | extern struct activity activity[MAX_THREADS]; |
| 31 | |
| 32 | |
| 33 | void report_stolen_time(uint64_t stolen); |
| 34 | |
| 35 | /* Collect date and time information before calling poll(). This will be used |
| 36 | * to count the run time of the past loop and the sleep time of the next poll. |
| 37 | */ |
| 38 | static inline void activity_count_runtime() |
| 39 | { |
| 40 | uint64_t new_mono_time; |
| 41 | uint64_t new_cpu_time; |
| 42 | int64_t stolen; |
| 43 | |
| 44 | new_cpu_time = now_cpu_time(); |
| 45 | new_mono_time = now_mono_time(); |
| 46 | |
| 47 | if (prev_cpu_time && prev_mono_time) { |
| 48 | new_cpu_time -= prev_cpu_time; |
| 49 | new_mono_time -= prev_mono_time; |
| 50 | stolen = new_mono_time - new_cpu_time; |
| 51 | if (unlikely(stolen >= 500000)) { |
| 52 | stolen /= 500000; |
| 53 | /* more than half a millisecond difference might |
| 54 | * indicate an undesired preemption. |
| 55 | */ |
| 56 | report_stolen_time(stolen); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | |
| 62 | #endif /* _PROTO_ACTIVITY_H */ |
| 63 | |
| 64 | /* |
| 65 | * Local variables: |
| 66 | * c-indent-level: 8 |
| 67 | * c-basic-offset: 8 |
| 68 | * End: |
| 69 | */ |