| 736 | } |
| 737 | |
| 738 | static __rte_always_inline int |
| 739 | get_timeout_cycles(struct rte_event_timer *evtim, |
| 740 | const struct rte_event_timer_adapter *adapter, |
| 741 | uint64_t *timeout_cycles) |
| 742 | { |
| 743 | static struct rte_reciprocal_u64 nsecpersec_inverse; |
| 744 | static uint64_t timer_hz; |
| 745 | uint64_t rem_cycles, secs_cycles = 0; |
| 746 | uint64_t secs, timeout_nsecs; |
| 747 | uint64_t nsecpersec; |
| 748 | struct swtim *sw; |
| 749 | |
| 750 | sw = swtim_pmd_priv(adapter); |
| 751 | nsecpersec = (uint64_t)NSECPERSEC; |
| 752 | |
| 753 | timeout_nsecs = evtim->timeout_ticks * sw->timer_tick_ns; |
| 754 | if (timeout_nsecs > sw->max_tmo_ns) |
| 755 | return -1; |
| 756 | if (timeout_nsecs < sw->timer_tick_ns) |
| 757 | return -2; |
| 758 | |
| 759 | /* Set these values in the first invocation */ |
| 760 | if (!timer_hz) { |
| 761 | timer_hz = rte_get_timer_hz(); |
| 762 | nsecpersec_inverse = rte_reciprocal_value_u64(nsecpersec); |
| 763 | } |
| 764 | |
| 765 | /* If timeout_nsecs > nsecpersec, decrease timeout_nsecs by the number |
| 766 | * of whole seconds it contains and convert that value to a number |
| 767 | * of cycles. This keeps timeout_nsecs in the interval [0..nsecpersec) |
| 768 | * in order to avoid overflow when we later multiply by timer_hz. |
| 769 | */ |
| 770 | if (timeout_nsecs > nsecpersec) { |
| 771 | secs = rte_reciprocal_divide_u64(timeout_nsecs, |
| 772 | &nsecpersec_inverse); |
| 773 | secs_cycles = secs * timer_hz; |
| 774 | timeout_nsecs -= secs * nsecpersec; |
| 775 | } |
| 776 | |
| 777 | rem_cycles = rte_reciprocal_divide_u64(timeout_nsecs * timer_hz, |
| 778 | &nsecpersec_inverse); |
| 779 | |
| 780 | *timeout_cycles = secs_cycles + rem_cycles; |
| 781 | |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | /* This function returns true if one or more (adapter) ticks have occurred since |
| 786 | * the last time it was called. |
no test coverage detected