WARP Project Forums - Wireless Open-Access Research Platform

You are not logged in.

#1 2017-Feb-07 08:13:00

nader
Member
Registered: 2016-May-24
Posts: 22

Different results from manual calculation

Hi,

I used the following formula to calculate the draining time of the buffer periodically using a scheduler in wlan_mac_ap.c . When I use xil_printf() to print the variable "t_drain", I found different results from manual calculation.

t_drain = (queue_num_queued(queue_sel) * 1428 * 8000000) / (active_bss_info->members.length * rate);

t_drain is defined as u64 local variable.
rate is defined as u32 local variable.

For example:
Queue ID: 2 - Active BSS: 1 - Rate: 27262976 - Queued: 83
Time to Drain: 121 which is not consistent with the right result.


I can't figure out what is the problem.

Offline

 

#2 2017-Feb-07 08:53:04

murphpo
Administrator
From: Mango Communications
Registered: 2006-Jul-03
Posts: 5159

Re: Different results from manual calculation

The numerator in your calculation exceeds 2^32 (1428 * 8000000 > 2^33). When the compiler interprets the constants as int values (the default for integer constants when no type is specified) the numerator calculation wraps, leading to the unexpected division output. Try casting each value in the expression as a (u64) so the compiler knows it should use 64-bit arithmetic for all steps of the calculation.

Offline

 

#3 2017-Feb-08 04:34:09

nader
Member
Registered: 2016-May-24
Posts: 22

Re: Different results from manual calculation

Problem solved. Thank you.

Offline

 

Board footer