Rev 4244 | Rev 6082 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4244 | Rev 5270 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include |
1 | #include |
Line 2... | Line 2... | ||
2 | 2 | ||
3 | 3 | ||
Line 129... | Line 129... | ||
129 | 129 | ||
130 | return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32) |
130 | return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32) |
131 | >> MSEC_TO_HZ_SHR32; |
131 | >> MSEC_TO_HZ_SHR32; |
132 | #endif |
132 | #endif |
- | 133 | } |
|
Line 133... | Line 134... | ||
133 | } |
134 | EXPORT_SYMBOL(msecs_to_jiffies); |
134 | 135 | ||
135 | unsigned long usecs_to_jiffies(const unsigned int u) |
136 | unsigned long usecs_to_jiffies(const unsigned int u) |
136 | { |
137 | { |
Line 143... | Line 144... | ||
143 | #else |
144 | #else |
144 | return (USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32) |
145 | return (USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32) |
145 | >> USEC_TO_HZ_SHR32; |
146 | >> USEC_TO_HZ_SHR32; |
146 | #endif |
147 | #endif |
147 | } |
148 | } |
- | 149 | EXPORT_SYMBOL(usecs_to_jiffies); |
|
Line -... | Line 150... | ||
- | 150 | ||
- | 151 | /* |
|
- | 152 | * The TICK_NSEC - 1 rounds up the value to the next resolution. Note |
|
- | 153 | * that a remainder subtract here would not do the right thing as the |
|
- | 154 | * resolution values don't fall on second boundries. I.e. the line: |
|
- | 155 | * nsec -= nsec % TICK_NSEC; is NOT a correct resolution rounding. |
|
- | 156 | * Note that due to the small error in the multiplier here, this |
|
- | 157 | * rounding is incorrect for sufficiently large values of tv_nsec, but |
|
- | 158 | * well formed timespecs should have tv_nsec < NSEC_PER_SEC, so we're |
|
- | 159 | * OK. |
|
- | 160 | * |
|
- | 161 | * Rather, we just shift the bits off the right. |
|
- | 162 | * |
|
- | 163 | * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec |
|
- | 164 | * value to a scaled second value. |
|
148 | 165 | */ |
|
149 | unsigned long |
166 | static unsigned long |
150 | timespec_to_jiffies(const struct timespec *value) |
167 | __timespec_to_jiffies(unsigned long sec, long nsec) |
151 | { |
- | |
152 | unsigned long sec = value->tv_sec; |
168 | { |
Line 153... | Line 169... | ||
153 | long nsec = value->tv_nsec + TICK_NSEC - 1; |
169 | nsec = nsec + TICK_NSEC - 1; |
154 | 170 | ||
155 | if (sec >= MAX_SEC_IN_JIFFIES){ |
171 | if (sec >= MAX_SEC_IN_JIFFIES){ |
156 | sec = MAX_SEC_IN_JIFFIES; |
172 | sec = MAX_SEC_IN_JIFFIES; |
Line 160... | Line 176... | ||
160 | (((u64)nsec * NSEC_CONVERSION) >> |
176 | (((u64)nsec * NSEC_CONVERSION) >> |
161 | (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC; |
177 | (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC; |
Line 162... | Line 178... | ||
162 | 178 | ||
Line -... | Line 179... | ||
- | 179 | } |
|
- | 180 | ||
- | 181 | unsigned long |
|
- | 182 | timespec_to_jiffies(const struct timespec *value) |
|
- | 183 | { |
|
- | 184 | return __timespec_to_jiffies(value->tv_sec, value->tv_nsec); |
|
- | 185 | } |
|
- | 186 | ||
- | 187 | EXPORT_SYMBOL(timespec_to_jiffies); |
|
- | 188 | ||
- | 189 | void |
|
- | 190 | jiffies_to_timespec(const unsigned long jiffies, struct timespec *value) |
|
- | 191 | { |
|
- | 192 | /* |
|
- | 193 | * Convert jiffies to nanoseconds and separate with |
|
- | 194 | * one divide. |
|
- | 195 | */ |
|
- | 196 | u32 rem; |
|
- | 197 | value->tv_sec = div_u64_rem((u64)jiffies * TICK_NSEC, |
|
- | 198 | NSEC_PER_SEC, &rem); |
|
- | 199 | value->tv_nsec = rem; |
|
- | 200 | } |
|
163 | } |
201 | EXPORT_SYMBOL(jiffies_to_timespec); |
164 | 202 | ||
165 | s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder) |
203 | s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder) |
Line 166... | Line 204... | ||
166 | { |
204 | { |