Documentation
¶
Overview ¶
Package core contains some generic helper functions for the package github.com/florianl/go-tc. Depending on the actual hardware in use, parameters to filters and qdiscs can vary to achieve the same behaviour.
If PROC_ROOT is set it will be used to lookup packet scheduler information from net/psched.
Index ¶
- func BuildHandle(maj, min uint32) uint32
- func Duration2TcTime(d time.Duration) (uint32, error)
- func FilterInfo(priority uint16, protocol uint16) uint32
- func GetClockFactor() float64
- func GetTickInUSec() float64
- func InitializeClock() error
- func IsClockInitialized() bool
- func Ktime2Time(ktime uint32) uint32
- func SetClockParameters(newClockFactor, newTickInUSec float64)
- func SplitHandle(handle uint32) (major, minor uint32)
- func Tick2Time(tick uint32) uint32
- func Time2Ktime(time uint32) uint32
- func Time2Tick(time uint32) uint32
- func XmitSize(rate uint64, ticks uint32) uint32
- func XmitTime(rate uint64, size uint32) uint32
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildHandle ¶
BuildHandle is a simple helper function to construct the handle for the Tcmsg struct
func Duration2TcTime ¶ added in v0.4.2
Duration2TcTime implements iproute2/tc/q_netem.c:get_ticks(). It converts a given duration into a time value that can be converted to ticks with Time2Tick(). On error it returns syscall.EINVAL.
func FilterInfo ¶ added in v0.4.5
FilterInfo is a simple helper to set the priority and protocol of the filter
func GetClockFactor ¶ added in v0.4.7
func GetClockFactor() float64
GetClockFactor returns the current clock factor value.
func GetTickInUSec ¶ added in v0.4.7
func GetTickInUSec() float64
GetTickInUSec returns the current tick in microseconds conversion factor.
func InitializeClock ¶ added in v0.4.7
func InitializeClock() error
InitializeClock initializes the clock parameters by reading from /proc/net/psched on Linux. On non-Linux platforms, it sets default values (1.0 for both parameters). This function must be called before using any of the timing functions. It returns an error if the clock parameters cannot be read on Linux.
Example ¶
ExampleInitializeClock demonstrates the clock initialization API
// Initialize clock parameters
if err := InitializeClock(); err != nil {
fmt.Printf("Warning: failed to initialize clock: %v\n", err)
// You can optionally set fallback values if initialization fails
SetClockParameters(1.0, 1.0)
}
// Set known values for predictable output
SetClockParameters(1.0, 1.0)
// Now you can use timing functions
ticks := Time2Tick(1000)
fmt.Printf("Time2Tick(1000) = %d\n", ticks)
// You can also get the current clock parameters
clockFactor := GetClockFactor()
tickInUSec := GetTickInUSec()
fmt.Printf("Clock Factor: %.1f, Tick in µs: %.1f\n", clockFactor, tickInUSec)
Output: Time2Tick(1000) = 1000 Clock Factor: 1.0, Tick in µs: 1.0
func IsClockInitialized ¶ added in v0.4.7
func IsClockInitialized() bool
IsClockInitialized returns true if the clock parameters have been initialized.
func Ktime2Time ¶
Ktime2Time implements iproute2/tc/tc_core:tc_core_ktime2time().
func SetClockParameters ¶ added in v0.4.7
func SetClockParameters(newClockFactor, newTickInUSec float64)
SetClockParameters allows manual configuration of the clock parameters. This is useful for testing or when custom clock values are needed. clockFactor is the clock resolution factor, tickInUSec is the tick to microsecond conversion factor.
func SplitHandle ¶
SplitHandle extracts the major and minor part from a given handle
func Tick2Time ¶
Tick2Time implements iproute2/tc/tc_core:tc_core_tick2time(). It returns a time in usec for a given number of CPU ticks.
func Time2Ktime ¶
Time2Ktime implements iproute2/tc/tc_core:tc_core_time2ktime().
func Time2Tick ¶
Time2Tick implements iproute2/tc/tc_core:tc_core_time2tick(). It returns the number of CPU ticks for a given time in usec.
Types ¶
This section is empty.