Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve scheduler #506

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/common/pf_alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
*/

#ifdef UNIT_TEST
#define os_get_current_time_us mock_os_get_current_time_us
#endif

/*
Expand Down Expand Up @@ -826,11 +827,12 @@ static void pf_alarm_apms_timeout (

if (
pf_scheduler_add (
net,
&net->scheduler_data,
p_apmx->timeout_us,
pf_alarm_apms_timeout,
p_apmx,
&p_apmx->resend_timeout) != 0)
&p_apmx->resend_timeout,
current_time) != 0)
{
LOG_ERROR (
PF_ALARM_LOG,
Expand Down Expand Up @@ -1460,11 +1462,12 @@ static int pf_alarm_apms_apms_a_data_req (
retransmission timer */
if (
pf_scheduler_add (
net,
&net->scheduler_data,
p_apmx->timeout_us,
pf_alarm_apms_timeout,
p_apmx,
&p_apmx->resend_timeout) != 0)
&p_apmx->resend_timeout,
os_get_current_time_us()) != 0)
{
LOG_ERROR (
PF_ALARM_LOG,
Expand Down Expand Up @@ -1549,7 +1552,9 @@ static int pf_alarm_apmx_close (pnet_t * net, pf_ar_t * p_ar, uint8_t err_code)
{
/* Free resources */
/* StopTimer */
pf_scheduler_remove_if_running (net, &p_ar->apmx[ix].resend_timeout);
pf_scheduler_remove_if_running (
&net->scheduler_data,
&p_ar->apmx[ix].resend_timeout);

p_ar->apmx[ix].p_ar = NULL;
p_ar->apmx[ix].apms_state = PF_APMS_STATE_CLOSED;
Expand Down
12 changes: 7 additions & 5 deletions src/common/pf_cpm_driver_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ static void pf_cpm_control_interval_expired (
/* Timer auto-reload */
if (
pf_scheduler_add (
net,
&net->scheduler_data,
p_iocr->cpm.control_interval,
pf_cpm_control_interval_expired,
arg,
&p_iocr->cpm.ci_timeout) != 0)
&p_iocr->cpm.ci_timeout,
current_time) != 0)
{
LOG_ERROR (
PF_CPM_LOG,
Expand Down Expand Up @@ -154,7 +155,7 @@ static int pf_cpm_driver_sw_close_req (
pf_cpm_t * p_cpm = &p_ar->iocrs[crep].cpm;

p_cpm->ci_running = false; /* StopTimer */
pf_scheduler_remove_if_running (net, &p_cpm->ci_timeout);
pf_scheduler_remove_if_running (&net->scheduler_data, &p_cpm->ci_timeout);

pf_eth_frame_id_map_remove (net, p_cpm->frame_id[0]);
if (p_cpm->nbr_frame_id == 2)
Expand Down Expand Up @@ -424,11 +425,12 @@ static int pf_cpm_driver_sw_activate_req (
}
pf_scheduler_init_handle (&p_cpm->ci_timeout, "cpm");
ret = pf_scheduler_add (
net,
&net->scheduler_data,
p_cpm->control_interval,
pf_cpm_control_interval_expired,
p_iocr,
&p_cpm->ci_timeout);
&p_cpm->ci_timeout,
os_get_current_time_us());
if (ret != 0)
{
LOG_ERROR (PF_CPM_LOG, "CPM_DRV_SW(%d): Timeout not started\n", __LINE__);
Expand Down
22 changes: 13 additions & 9 deletions src/common/pf_dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/

#ifdef UNIT_TEST
#define os_get_current_time_us mock_os_get_current_time_us
#endif

#include <string.h>
Expand Down Expand Up @@ -241,11 +242,12 @@ static void pf_dcp_restart_sam_timeout (pnet_t * net, const pnet_ethaddr_t * mac

memcpy (&net->dcp_sam, mac, sizeof (net->dcp_sam));
(void)pf_scheduler_restart (
net,
&net->scheduler_data,
PF_DCP_SAM_TIMEOUT,
pf_dcp_clear_sam,
NULL,
&net->dcp_sam_timeout);
&net->dcp_sam_timeout,
os_get_current_time_us());
}

/**
Expand Down Expand Up @@ -588,7 +590,6 @@ static int pf_dcp_get_req (
* @param current_time In: The current system time, in microseconds,
* when the scheduler is started to execute
* stored tasks.
* Not used here.
*/
static void pf_dcp_control_signal_led (
pnet_t * net,
Expand Down Expand Up @@ -626,11 +627,12 @@ static void pf_dcp_control_signal_led (

/* Schedule another round */
(void)pf_scheduler_add (
net,
&net->scheduler_data,
PF_DCP_SIGNAL_LED_HALF_INTERVAL,
pf_dcp_control_signal_led,
(void *)(uintptr_t)state,
&net->dcp_led_timeout);
&net->dcp_led_timeout,
current_time);
}
else
{
Expand All @@ -657,11 +659,12 @@ int pf_dcp_trigger_signal_led (pnet_t * net)
"DCP(%d): Received request to flash LED\n",
__LINE__);
(void)pf_scheduler_add (
net,
&net->scheduler_data,
PF_DCP_SIGNAL_LED_HALF_INTERVAL,
pf_dcp_control_signal_led,
(void *)(2 * PF_DCP_SIGNAL_LED_NUMBER_OF_FLASHES - 1),
&net->dcp_led_timeout);
&net->dcp_led_timeout,
os_get_current_time_us());
}
else
{
Expand Down Expand Up @@ -1942,11 +1945,12 @@ static int pf_dcp_identify_req (
#endif

(void)pf_scheduler_add (
net,
&net->scheduler_data,
response_delay,
pf_dcp_responder,
p_rsp,
&net->dcp_identresp_timeout);
&net->dcp_identresp_timeout,
os_get_current_time_us());

/* Note: Do not free p_rsp, it is used in pf_dcp_responder() */
}
Expand Down
7 changes: 4 additions & 3 deletions src/common/pf_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
*/

#ifdef UNIT_TEST
#define pnal_clear_file mock_pnal_clear_file
#define pnal_load_file mock_pnal_load_file
#define pnal_save_file mock_pnal_save_file
#define pnal_clear_file mock_pnal_clear_file
#define pnal_load_file mock_pnal_load_file
#define pnal_save_file mock_pnal_save_file
#define os_get_current_time_us mock_os_get_current_time_us
#endif

#include "pf_includes.h"
Expand Down
30 changes: 20 additions & 10 deletions src/common/pf_lldp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifdef UNIT_TEST
#define pnal_get_system_uptime_10ms mock_pnal_get_system_uptime_10ms
#define pnal_get_interface_index mock_pnal_get_interface_index
#define os_get_current_time_us mock_os_get_current_time_us
#endif

#define STRINGIFY(s) STRINGIFIED (s)
Expand Down Expand Up @@ -509,7 +510,9 @@ void pf_lldp_restart_peer_timeout (
{
pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num);

pf_scheduler_remove_if_running (net, &p_port_data->lldp.rx_timeout);
pf_scheduler_remove_if_running (
&net->scheduler_data,
&p_port_data->lldp.rx_timeout);

/*
* Profinet states that the time to live shall be 20 seconds,
Expand All @@ -528,11 +531,12 @@ void pf_lldp_restart_peer_timeout (

if (
pf_scheduler_add (
net,
&net->scheduler_data,
timeout_in_secs * 1000000,
pf_lldp_receive_timeout,
p_port_data,
&p_port_data->lldp.rx_timeout) != 0)
&p_port_data->lldp.rx_timeout,
os_get_current_time_us()) != 0)
{
LOG_ERROR (
PF_LLDP_LOG,
Expand All @@ -545,7 +549,9 @@ void pf_lldp_stop_peer_timeout (pnet_t * net, int loc_port_num)
{
pf_port_t * p_port_data = pf_port_get_state (net, loc_port_num);

pf_scheduler_remove_if_running (net, &p_port_data->lldp.rx_timeout);
pf_scheduler_remove_if_running (
&net->scheduler_data,
&p_port_data->lldp.rx_timeout);
}

/**
Expand Down Expand Up @@ -1081,7 +1087,7 @@ static void pf_lldp_send (pnet_t * net, int loc_port_num)
*
* @param net InOut: The p-net stack instance
* @param arg In: Reference to port_data
* @param current_time In: Not used.
* @param current_time In: Current time, in microseconds
*/
static void pf_lldp_trigger_sending (
pnet_t * net,
Expand All @@ -1094,11 +1100,12 @@ static void pf_lldp_trigger_sending (

if (
pf_scheduler_add (
net,
&net->scheduler_data,
PF_LLDP_SEND_INTERVAL * 1000,
pf_lldp_trigger_sending,
p_port_data,
&p_port_data->lldp.tx_timeout) != 0)
&p_port_data->lldp.tx_timeout,
current_time) != 0)
{
LOG_ERROR (
PF_LLDP_LOG,
Expand All @@ -1122,11 +1129,12 @@ static void pf_lldp_tx_restart (pnet_t * net, int loc_port_num, bool send)

if (
pf_scheduler_restart (
net,
&net->scheduler_data,
PF_LLDP_SEND_INTERVAL * 1000,
pf_lldp_trigger_sending,
p_port_data,
&p_port_data->lldp.tx_timeout) != 0)
&p_port_data->lldp.tx_timeout,
os_get_current_time_us()) != 0)
{
LOG_ERROR (
PF_ETH_LOG,
Expand Down Expand Up @@ -1183,7 +1191,9 @@ void pf_lldp_send_disable (pnet_t * net, int loc_port_num)
"LLDP(%d): Disabling LLDP transmission for port %d\n",
__LINE__,
loc_port_num);
pf_scheduler_remove_if_running (net, &p_port_data->lldp.tx_timeout);
pf_scheduler_remove_if_running (
&net->scheduler_data,
&p_port_data->lldp.tx_timeout);
}

/**
Expand Down
16 changes: 11 additions & 5 deletions src/common/pf_ppm_driver_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <string.h>
#include <inttypes.h>

#ifdef UNIT_TEST
// TODO #define os_get_current_time_us mock_os_get_current_time_us
#endif

/**
* @internal
* Send the process data frame.
Expand Down Expand Up @@ -54,11 +58,12 @@ static void pf_ppm_drv_sw_send (pnet_t * net, void * arg, uint32_t current_time)
delay = p_arg->ppm.next_exec - current_time;
if (
pf_scheduler_add (
net,
&net->scheduler_data,
delay,
pf_ppm_drv_sw_send,
arg,
&p_arg->ppm.ci_timeout) == 0)
&p_arg->ppm.ci_timeout,
current_time) == 0)
{
p_arg->ppm.trx_cnt++;
if (p_arg->ppm.first_transmit == false)
Expand Down Expand Up @@ -97,11 +102,12 @@ int pf_ppm_drv_sw_activate_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep)

pf_scheduler_init_handle (&p_ppm->ci_timeout, "ppm");
ret = pf_scheduler_add (
net,
&net->scheduler_data,
p_ppm->control_interval,
pf_ppm_drv_sw_send,
p_iocr,
&p_ppm->ci_timeout);
&p_ppm->ci_timeout,
os_get_current_time_us());

return ret;
}
Expand All @@ -118,7 +124,7 @@ int pf_ppm_drv_sw_close_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep)
p_ar->arep,
crep);

pf_scheduler_remove_if_running (net, &p_ppm->ci_timeout);
pf_scheduler_remove_if_running (&net->scheduler_data, &p_ppm->ci_timeout);

return 0;
}
Expand Down
Loading