Joint Task Offloading and Resource Allocation for Obtaining Fresh Status Updates in Multi-Device MEC Systems

To improve the operational efficiency of smart city, smart devices extract informative status updates from sampled image and video data to intelligently monitor the surroundings. Mobile edge computing (MEC) is considered as an emerging technology to provide energy-constrained devices with enhanced computation capability by offloading tasks to nearby servers. In such circumstance, the freshness of obtained status updates is critical to system performance, which can be characterized by the concept of age of information (AoI). Due to resource contention among multiple devices, the problem of how to maintain the timeliness of task executing is not trivial. In this paper, we are interested in minimizing the age of obtained status updates by jointly optimizing task generation, computation offloading as well as communication and computational resource allocation under the average energy constraint at each device. To tackle the time couplings of task generation and computation offloading decisions, we leverage the Lyapunov optimization technique to convert the long-term stochastic optimization problem into a per-time slot deterministic optimization problem. In each time slot, an online algorithm is proposed to determine the task offloading and computation offloading strategy. Moreover, we theoretically prove that the proposed algorithm can be arbitrarily close to the optimal performance with the gap of ${\mathcal{ O}}\left ({{{1 \mathord {\left /{ {\vphantom {1~V}} }\right. } V}} }\right)$ . Simulation results show that our proposed scheme achieves better performance when compared with existing schemes.


I. INTRODUCTION
As the world is quickly becoming urbanized, Internet of Things (IoT) devices are employed to improve the operational efficiency of a city by realizing innovative applications such as intelligent surveillance, vehicular networks, and smart factory, where the primary function of end devices is no longer data collection [1], [2]. Instead, end devices perceive the physical environment by extracting informative system status updates from its sampled multimedia files (e.g., images or videos) and initiate control actions [1]- [4]. Due to the dynamic nature of environment, end devices require continuous and valuable system status updates to achieve real-time awareness of its surroundings and make The associate editor coordinating the review of this manuscript and approving it for publication was M. Anwar Hossain .
control decisions in a timely manner. In such circumstance, the timeliness of obtained status updates and energy efficiency are two most prevalent concerns. Considering the limited battery capacity and built-in computational resources at end devices, mobile edge computing (MEC) has been recognized as a promising solution to enhance the computation capability of end devices by offloading computationintensive tasks to a nearby edge server [5], [6]. In this paper, we are interested in investigating how to guarantee the timeliness of obtained status updates in a multi-device MEC system.
In the presence of multiple devices, the main challenge is how to properly allocate the limited and time-varying network resources among the devices to ensure the freshness of obtained status updates at each device. Note that in order to obtain fresh status updates, each device tends to sample as frequently as possible and extracts status updates from the sampled data as fast as possible by immediately offloading tasks to the MEC server for execution at full speed. However, since multiple devices have to share the limited communication and computational resources, generating tasks blindly at each device would lead to network congestion and queueing at the edge server, which would degrade the system performance. Therefore, to realize timely task generation and execution among devices, we aim to tackle the problems of how to measure the freshness of obtained status updates and how to adaptively optimize the usage efficiency of timevarying network resources.
First, to quantify the freshness of obtained status updates, we use the concept of age of information (AoI), which is defined as the time elapsed since the latest received data packet is generated at the data source [7], [8]. Different from the existing system design which targets at the energy consumption or transmission delay minimization, the AoI based performance metric jointly considers the time interval between two consecutive samples, transmission delay, and computation delay, which fully captures the temporal characteristics of the three steps for obtaining a status update, namely task generation, task offloading, and task execution. Moreover, since there exist the couplings of data transmission and execution decisions among all devices, the availability and state of communication and computational resources are stochastic for devices at different time slots [5], [9]. The optimal decision is hindered by the need for complete network states over a long period of time. Therefore, we employ the Lyapunov optimization approach [10] to convert the long-term stochastic optimization problem into a deterministic optimization problem in each time slot and propose an online algorithm to perform task generation and computation offloading decision based on the current network states.
In this paper, we consider a general MEC system with multiple devices, where each device continuously monitors its surroundings and obtains status updates by extracting valuable information from the sampled data. To ensure the timely execution of task generated at multiple devices, we investigate a joint task generation and computation offloading strategy with the aim of minimizing the weighted sum of age of obtained status updates at all devices. Since the coupling of decisions among multiple devices cannot be ignored, the strategy design is not trivial. First, we formulate an age minimization problem by jointly considering the average energy constraint at each device, the time-varying wireless channel, and the stochasticity of computational resources at MEC servers. Moreover, an online decision-making algorithm is proposed to obtain an effective age-based task generation and computation offloading policy.
A. RELATED WORK 1) MOBILE EDGE COMPUTING Recent years have seen research progress on MEC for both single-user and multi-user MEC systems. In [11], the authors investigated the network architectures and protocols for MEC in 5G wireless networks. For single-user MEC systems, the authors jointly optimized the computational speed, transmission power of devices, and offloading ratio to minimize the energy consumption of devices and the latency of application execution in [12]. The authors in [13] exploited the time-varying channel and helper-CPU states to minimize the energy consumption of devices. The authors in [14] investigated the MEC system with an energy harvesting device and developed an online algorithm to minimize the execution cost (i.e., execution delay and task failure). In [15], an optimal task scheduling policy was proposed to minimize the average delay of each task under the average power consumption of devices. For multi-user MEC systems, the computation offloading design is more complicated. In particular, one of the main issues is how to jointly assign communication and computational resources. In [16], the authors investigated joint communication and computational resource allocation to minimize the weighted-sum delay of all devices for a time-division multiple access (TDMA)-MEC system. In [17], the authors proposed two algorithms based on the Dinkelbach method and the Newton method respectively to minimize the offloading delay for non-orthogonal multiple access (NOMA) assisted MEC and proved the optimality of both algorithms. In [18], the authors employed an iterative procedure to extend the two-user scenario to a multi-user one and studied the delay minimization for offloading in a multi-user NOMA-MEC network. The authors in [19] proposed a low-complexity iterative algorithm by jointly considering heterogeneous computational resources and power allocation to minimize the energy consumption of devices. In [20], the authors obtained the optimal offloaded data size and power allocation at devices by using the Lagrangian dual method in a wireless powered MEC system. In [21], the authors developed a new quantized dynamic programming algorithm to minimize the total energy consumption of devices under latency constraints. An efficient online task scheduling algorithm was proposed to solve a novel multivehicle and multi-task offloading problem in [22].
In prior works, the computation tasks at devices are considered independent, and the value of tasks is not considered to degrade over time. The objectives employed are usually minimizing the energy consumption [13], [19]- [22] or delay [12], [14]- [18] of processing independent tasks. Therefore, in such scenarios, the offloading decision can be made based on channel states and available computational resources at MEC servers. However, in this paper, our goal is to obtain fresh status updates by processing tasks generated at devices. Besides the energy consumption and delay of processing individual tasks, we also need to take the temporal value evolution characteristics among consecutive tasks into consideration. Under the energy constraint at each device, the generation of tasks should be distributed over a long period of time so that the obtained status updates are always fresh, and the generated tasks should be processed in the most efficient way (local computing or offloading). Moreover, in case VOLUME 8, 2020 of multiple devices, the task generation and computation offloading decision problem becomes more complicated due to the resource contention among devices.

2) AGE OF INFORMATION
Most of the works on AoI mainly study the AoI performance and the status update policy under the energy constraint for the single node case. In [23], the optimal status update policies were proposed to minimize the average AoI for an energy harvesting source equipped with different battery sizes. In [24], the authors investigated the age-energy tradeoff in the IoT monitoring system adopting the truncated automatic repeat request scheme. The authors in [25] employed the queueing theory to investigate the non-linear AoI-based performance by considering the randomness in status packet generation and energy harvesting. In [26], the authors used a non-decreasing penalty function of AoI to measure the timeliness of status updates and showed that the optimal policy was a monotone threshold policy. In addition, many other works about AoI investigate the transmission scheduling of status updates in the multi-node case. In [27], the authors developed a throughput-optimal age-based scheduling algorithm to optimally support coexisting persistent and dynamic flows. The authors in [28] proposed low-complexity scheduling policies to minimize the weighted-sum AoI for general broadcast networks. In [29], the authors investigated the problem of minimizing the weighted-sum AoI under the throughput constraints from the nodes. The authors in [30] jointly optimized data sampling and link scheduling to achieve the best network-level data freshness in multi-hop cyber-physical systems. In [31], the authors proposed an integer linear programming formulation of the minimum age scheduling problem (MASP) and developed a sub-optimal steepest age descent algorithm to solve the MASP.
Most existing works on AoI mainly focus on age-based scheduling for data transmission, where the transmission energy consumption is assumed to be fixed [23]- [26] and the number of available wireless channels is limited [27]- [31]. In a multi-device MEC system, besides limited communication resources, limited computational resources also constrain the system performance. Due to the couplings of task generation and offloading decisions among multiple devices, how to obtain an age-optimal resource allocation scheme under stochastic communication and computational resources is challenging. Moreover, since the energy consumption of offloading a task is critical for offloading decision, the transmission energy consumption should vary in different time slots based on channel states, instead of being assumed to be fixed. Therefore, it is not trivial to schedule the task generation and computation offloading among multiple devices for obtaining the freshest status updates with minimum energy consumption. Under the average energy constraint at each device over a long period of time, the optimal decision requires complete non-causal information of networks [32] or a priori knowledge on the statistics of stochastic processes [33], [34]. However, it is unpractical to collect the information beforehand. Therefore, we are motivated to convert the long-term stochastic optimization problem into a per-time slot deterministic optimization problem and design a light-weight online decision policy.

B. CONTRIBUTION
In this paper, we investigate a stochastic control problem of task generation and computation offloading to maintain the freshness of status updates obtained by executing tasks in a multi-device MEC system. The contributions of this paper are summarized as follows: • To ensure the freshness of obtained status updates in a multi-device MEC system, we employ the concept of AoI to quantify the temporal value of obtained status updates and formulate an age minimization problem by jointly considering the average energy constraint at each device and the stochastic computational and communication resources.
• To solve the long-term stochastic optimization problem, we decouple the time couplings of task generation and computation offloading decisions by leveraging the Lyapunov optimization technique and then convert it to a per-time slot deterministic optimization problem.
• To obtain the age-optimal task generation and computation offloading policy for real-time systems, we propose a low-complexity online algorithm. Moreover, we theoretically prove that the proposed algorithm preserves the asymptotic optimality with a known deviation.
The remainder of this paper is organized as follows.
In Section II, we introduce the system model. Section III presents the problem formulation of the age minimization problem in a multi-device MEC system. Section IV reformulates the age minimization problem. In Section V, we propose an online decision-making algorithm and analyze its performance theoretically. Simulation results are presented in Section VI. Finally, we conclude this paper in Section VII.

II. SYSTEM MODEL
In this section, we first describe the system architecture of a multi-device MEC system. Then, we present the age of obtained status updates model and the computing model.

A. MULTI-DEVICE MEC SYSTEM
As shown in Fig.1, we consider a multi-device MEC system consisting of an access point (AP) equipped with an MEC server and a set of M mobile devices, with M = |M| being the total number of mobile devices. In this system, each mobile device monitors the status of its surroundings by using embedded cameras or sensors and obtains informative status updates by processing multimedia files (e.g., objects detected in collected images or videos). The AP is equipped with an MEC server through wired connections, where the AP can be accessed by mobile devices over the wireless channel and the MEC server executes computation tasks from mobile devices. The multi-device MEC system is assumed to be a timeslotted system, t ∈ T = {0, 1, 2, · · · , T − 1} with the length of time slot τ . The system bandwidth is divided into multiple orthogonal subchannels and each subchannel can be allocated to at most one device. In each time slot, the device records the age of obtained status updates by using counters [34], obtains the channel state by measuring the pilot from the AP [35], [36], and feeds the age of obtained status updates and channel state information back to the AP. Based on these feedbacks and available computational and communication resources, the AP decides which devices offload generated tasks to the MEC server and allocates corresponding computational resources and wireless channels to devices.

B. AGE OF OBTAINED STATUS UPDATES MODEL
In the considered multi-device MEC system, with the assistance of the MEC server, each device obtains status updates by extracting valuable status information from sampled data to intelligently monitor the surroundings. In each time slot t, if the state information at the mobile device is out of date and the device has enough energy, this device gets a new status update by processing a computation task (i.e., local computing or offloading); otherwise, the device does not generate tasks for updating state information. Let u i (t) ∈ U , U = {no, loc, off} denote the status update action of device i in time slot t, where u i (t) = no indicates that the device i has no status updates; u i (t) = loc indicates that the device i obtains status updates by local computing; u i (t) = off indicates that the device i obtains status updates by offloading tasks for the MEC server execution.
In this paper, based on AoI, the age of obtained status updates model is proposed to measure the freshness of obtained status updates. We define the age of obtained status updates at the device as the time elapsed since the most recent generated task at the device was executed. Then, we set A i (t) = t − δ i (t) as the age of obtained status updates at device i at the beginning of time slot t, where δ i (t) indicates the time slot during which the device i obtained the latest status update by processing one task. In particular, if the device i does not obtain status updates (i.e., u i (t) = no), the age at device i increases by one. If the device i obtains a status update by either local computing (i.e., u i (t) = loc) or offloading the task for the MEC server execution (i.e., u i (t) = off), the age at device i drops to one. Therefore, the age of obtained status updates at device i at the beginning of time slot t can be denoted by Here, the processing of each generated task is completed during a time slot.

C. COMPUTING MODEL
In this paper, we consider the task model for binary offloading [5]. Each generated computation task is highly or relatively simple, i.e., cannot be partitioned, such as speech recognition and natural language translation [37], and can either be executed at the device or be offloaded to and executed at the MEC server within one time slot.

1) LOCAL COMPUTING
For local computing, the CPU at each device is assumed to operate at the CPU-cycle frequency f (in cycles per second) within one time slot. Here, we represent C as the inputbits of each generated task and obtain that wC CPU cycles are needed to complete the processing of one task, where w is the number of CPU cycles required for processing 1 bit data, which varies based on different application types. Hence, we have the CPU-cycle frequency of the device for executing one task locally within one time slot f = wC τ . Moreover, following the model in [13], E cyc = ξ f 2 represents the energy consumption of each CPU cycle at the device, where ξ is a constant. Therefore, we have the energy consumption of executing each task at the device, as given by

2) COMPUTATION OFFLOADING
In order to offload tasks for the MEC server execution, the input-bits of tasks need to be transmitted to the MEC server. Due to the other uplink traffic to the AP, the number of available subchannels is stochastic for the devices, which is represented as K (t). Moreover, the independent and identically distributed (i.i.d) block fading channel is assumed, namely that the channel remains unchanged within each time slot and varies across different time slots [9], [14]. Here, the channel state is defined as the ratio of the channel power gain between the device and the AP to the noise power at the AP. By exploiting the channel reciprocity in time-division mode systems, the device can obtain the channel state by measuring the pilot from the AP and feed the channel state information back to the AP [35], [36]. We denote h i (t) as the channel state in the uplink of device i in time slot t and VOLUME 8, 2020 assume that the channel process {h i (t)} is distributed based on a distribution p H (h), where H indicates the finite channel state space. For the device i, when the channel state is h i (t), the uplink data rate can be denoted by where W is the subchannel bandwidth and p i is the uplink transmission power of device i. Then, when the channel state is h i (t), the energy consumed by device i to successfully transmit the input-bits of one task to the MEC server is represented as Hence, the energy consumption of each device i in each time slot t can be expressed as Here, we consider that is the maximum energy consumption of executing one task at device i.
Moreover, since the other concurrent services need to be executed at the MEC server, the available computational resource at the MEC server is also stochastic for devices. Here, we denote F (t) as the total available computational resources at the MEC server in cycles per second in time slot t. After receiving the offloaded task from device i, the MEC server allocates the computational resources f i (t) in cycles per second to the device for executing tasks. Therefore, for device i, the total time of offloading a task for the MEC server execution in time slot t can be denoted by where D tra denote the data transmission time and the MEC server execution time, respectively. Note that the computation result is generally much smaller than the input-size of task, and thus the transmission delay for feedback is assumed to be negligible [14], [21].

III. PROBLEM FORMULATION
In this section, we present the problem formulation to study the age minimization problem under the average energy constraint at each device in a multi-device MEC system.

A. ENERGY CONSUMPTION CONSTRAINTS
Because of the limited battery capacity at the device, we consider that the average energy consumption at each device i is below a threshold E th i , as given by

B. COMPUTATION OFFLOADING CONSTRAINTS
Here, we consider that in each time slot, all offloaded tasks from devices need to be executed within one time slot.
In other words, if device i decides to offload a task to the MEC server for executing in time slot t, the processing of this offloaded task needs to be completed in this time slot by using the allocated computational resources f i (t) and the allocated subchannel (i.e., the uplink channel state h i (t)). Hence, we have denotes the indicator function. Note that since the MEC server execution time (D ser i (t) = 0) cannot achieve task offloading, the case D tra

C. COMPUTATIONAL RESOURCE ALLOCATION CONSTRAINTS
Although all devices can offload tasks to the MEC server for executing, the total computational resources allocated to devices are no more than the available computational resources at MEC servers. Therefore, we have where

D. SUBCHANNEL ALLOCATION CONSTRAINTS
Similar to computational resources at the MEC server, the total number of subchannels allocated to devices does not exceed that of available subchannels, as given by Note that if the device decides to offload tasks to the MEC server for executing, the AP assigns a subchannel to it for the transmission of input-bits of the task. Therefore, we obtain that the offloading decision also represents the subchannel allocation decision for all devices.
To maintain the freshness of obtained status updates at all devices, we aim to minimize the weighted-sum average age of obtained status updates at all devices. The weightedsum average age of obtained status updates at all devices is denoted by where the positive weight factors {α i }, ∀i ∈ M account for the fairness among devices. Then our problem can be formulated as follows: The formulated problem (P1) falls in the category of a longterm stochastic optimization problem. The optimal solution can be obtained offline only if the AP is assumed to have all the system parameters (e.g., channel state, age of obtained status updates at each device, and the status of computational resource at MEC servers) of all time slots. However, it is infeasible and unpractical for the AP to obtain these parameters in prior. Therefore, we propose an online algorithm to efficiently make task generation and computation offloading decisions based on the current network state.

IV. PROBLEM REFORMULATION
In order to visually see the benefit of each task generation and computation offloading decision, the objective function is reformulated. Fig.2 shows the age evolution of obtained status updates at device i. From Fig.2, we can observe that if device i does not obtain status updates, the age of obtained status updates will continue to increase until an entire triangle area is got. However, if the device i obtains a status update by locally executing a task or offloading a task to the MEC server for executing, the part of the area will be reduced, as shown in the shadow area of Fig.2. Moreover, after device i obtains one status update by executing one task in time slot t, the reduced area defined as the utility obtained by one status update can be calculated as Therefore, we can see that minimizing the weighted-sum average age of obtained status updates at all devices can be equivalent to maximizing the weighted-sum average utility at all devices, denoted by ϕ. The age minimization problem is now reformulated as s.t. (7), (8), (9), (10), (11).

V. ONLINE TASK GENERATION AND COMPUTATION OFFLOADING FOR MULTIPLE DEVICES
In this section, we first transform the long-term stochastic optimization problem (P2) into a per-time slot deterministic optimization problem by employing the Lyapunov optimization technique. Then, we develop an online task generation and computation offloading algorithm. Moreover, we analyze the stability of virtual queue and prove that the proposed algorithm achieves asymptotically optimal performance.

A. LYAPUNOV OPTIMIZATION
First, we show how the average energy constraint at each device can be transformed into a queue stability problem.
Here, in order to achieve this, we define the queue stability, as given by Definition 1: A discrete time process Q (t) is mean rate stable [10] if Lemma 1: Define a virtual queue Z i (t) and denote the virtual queue backlog as Therefore, according to Lemma 1, we can transform the average energy consumption constraint at each device (7) into a queue stability problem by defining the virtual queue Z i (t) for each device i.
Then, to solve the time coupling of decisions in the problem (P2), we define the Lyapunov function as VOLUME 8, 2020 and employ the conditional Lyapunov drift to push the backlog in the virtual queue towards a lower congestion state, which maintains the queue stability, as given by where (t) = [Z (t)] denotes the vector of all current virtual queue backlogs, Z (t) = {Z i (t) |i ∈ M}. Moreover, according to the Lyapunov optimization approach, we minimize the drift-plus-penalty expression, as denoted by where V is a non-negative parameter that adjusts the tradeoff between the weighted-sum average utility at all devices and the average virtual queue backlog at each device (i.e., the weighted-sum average age of obtained status updates at all devices and the average energy consumption at each device).

Lemma 2: For the observed virtual queue backlogs and any optimization decisions made in time slot t, the drift-pluspenalty for any time slot t satisfies the following inequality:
Proof: See Appendix B. Here, we observe that it is still difficult to minimize V ( (t)) because of its dynamics. Therefore, according to the concept of opportunistically minimizing an expectation [10], we are interested in minimizing the right-hand-side of (21) under the constraints (8), (9), (10), and (11), as given by where

B. ONLINE OPTIMIZATION OF TASK GENERATION AND COMPUTATION OFFLOADING
In this subsection, we propose an online task generation and computation offloading algorithm to address the above problem (P3). First, we do not consider the constraints (8), , (10), and (11). In order to minimize • Case e: if a i (t) < 0, b i (t) ≥ 0, then u i (t) = off. Therefore, without considering the constraints (8), (9), (10), and (11), each device i can obtain the optimal status update action by calculating a i (t) and b i (t) based on Z i (t), A i (t), E off (h i (t)) and E loc . Then, we consider these constraints (8), (9), (10), and (11). For case (a), case (c) and case (d), since these constraints do not affect the status update decisions of these devices, the devices in case (a) and case (d) obtain status updates by locally executing tasks (loc), and the devices in case (c) do not generate tasks to obtain status updates (no) in this time slot. However, for case (b) and case (e), due to the computation offloading constraints and the limited computational resources at MEC servers and wireless subchannels, some of the devices in case (b) and case (e) may not be allowed to offload tasks to the MEC server for executing. Therefore, we need to reconsider the status update decisions of devices in case (b) and case (e) under these constraints.
Under the constraints (8), (9), (10), and (11), the computational resource and subchannel allocation problem is actually a knapsack problem. For the knapsack problem, the optimal solution can be obtained by choosing the ''item'' with higher profit to fill the capacity of knapsack [38]. To solve the problem (P3), we denote −a i (t) as the profit of an item i and K (t) or F (t) as the knapsack capacity, respectively. Note that the devices that do not meet the constraint (9) in case (b) and case (e) cannot be allowed to offload tasks to the MEC server for executing, where M b1 and M e1 denote the set of devices that do not meet the constraint (9) in case (b) and case (e), respectively. Then, we sort the devices that meet the constraint (9) in case (b) and case (e) in the ascending order of a i (t) , i ∈ M b2 ∪ M e2 , i.e., a i (t) ≤ a j (t) for i < j, where M b2 and M e2 represent the set of devices that meet the constraint (9) in case (b) and case (e), respectively.
Here, we define the breaking item as the first device to which the computational resources of MEC servers or wireless subchannels are not allocated, the index of which can be denoted by Thus the AP allows the device i, i ∈ {j|j < d, j ∈ M b2 ∪ M e2 } to offload tasks to the MEC server for executing and allocates the computational resources f i (t) and a subchannel to it. Moreover, in order to minimize M i=1 i (t), the devices that are not allowed to offload tasks to the MEC server in case (b) and the case (e) will obtain status updates by locally executing tasks (loc) and not generate tasks to obtain status updates (no) respectively in this time slot. Therefore, we conclude that all devices in case (b) and case (e) perform the optimal status update action according to Note that in order to obtain the optimal status update actions of all devices under these constraints (8), (9), (10), and (11), the devices need to record the virtual queue backlogs and age of obtained statue updates, measure channel states, and feed these information back to the AP. Then, the AP decides which devices can offload tasks to the MEC server for executing according to these feedbacks and the current available computational resources at MEC servers and wireless subchannels. Here, we observe that without the coordination of the AP, each device in case (a), case (c) and case (d) can obtain the optimal status update action based on the virtual queue backlog, age of obtained status updates, channel state and local computing parameter at devices. In addition, since the devices that are allowed to offload tasks to the MEC server are selected from the devices in case (b) and case (e), the feedbacks of the devices in case (a), case (c) and case (d) cannot contribute the optimization of task offloading. Therefore, we have that the devices in case (a), case (c) and case (d) do not need to feed the virtual queue backlogs, age of obtained status updates and channel states back to the AP, which reduces feedbacks in each time slot. The online optimization of task generation and computation offloading is summarized in Algorithm 1.
In Algorithm 1, all devices can be divided into five groups in case (a)-case (e) by calculating a i (t) and b i (t) in each time slot. Each device i in case (a), case (c) and case (d) can obtain the optimal decision directly according to the values of a i (t) and b i (t). As for devices in case (b) and case (e), the formulated knapsack problem has to be solved to obtain the optimal decision. To solve the problem, we need to perform a sorting of the requesting devices which have enough communication resources to offload the task within one time slot (satisfying the computation offloading constraints (9)). It can be achieved by using the quicksort algorithm with a computational complexity of O ((|M b2 | + |M e2 |) log (|M b2 | + |M e2 |)) [39]. Therefore, the computational complexity of Algorithm 1 is given by O ((|M b2 | + |M e2 |) log (|M b2 | + |M e2 |)).

C. PERFORMANCE ANALYSIS
In this subsection, we analyze the stability of virtual queue and the average weighted-sum utility performance. Before doing these, according to [10], we have that for any σ > 0, there exists a feasible randomized stationary control policy that determines the task generation and computation Algorithm 1 Online Optimization of Task Generation and Computation Offloading 1: At each device i: 2: Obtain h i (t), and calculate Z i (t), Obtain status updates by local computing (i.e., u i (t) = loc) 5: else if a i (t) < 0, b i (t) < 0, a i (t) < b i (t) then 6: Send the request of task offloading to the AP, and feed back h i (t), Z i (t) and A i (t) to the AP 7: else if a i (t) ≥ 0, b i (t) ≥ 0 then 8: Do not obtain status updates (i.e., u i (t) = no) 9: else if a i (t) ≥ 0, b i (t) < 0 then 10: Obtain status updates by local computing (i.e., u i (t) = loc) 11: else if a i (t) < 0, b i (t) ≥ 0 then 12: Send the request of task offloading to the AP, and feed back h i (t), Z i (t) and A i (t) to the AP 13: end if 14: At the AP: 15: Collect the request of task offloading from each device i in case (b) and case (e) 16: Obtain K (t) and F (t) 17: Control each device i in case (b) and case (e) to take the status update action based on (24) and allocate available computational resources at MEC servers and wireless subchannels to devices offloading decisions of all devices (u * i (t) , i ∈ M) in each time slot, which satisfies where E * i (t) and ϕ * (t) are the results under the feasible stationary policy. ϕ opt is the theoretical optimal value of ϕ under the constraints (7), (8), (9), (10), and (11) in the problem (P1).

1) VIRTUAL QUEUE STABILITY
To online optimize task generation and computation offloading of all devices, we transform the average energy constraint at each device into a queue stability problem. Then, we propose an online optimization algorithm for task generation and computation offloading by incorporating the average energy constraint into the process of Lyapunov optimization. Theorem 1 shows that the average energy constraint at each device is satisfied under the proposed algorithm (i.e., Algorithm 1) based on Lemma 1.
Theorem 1: Assume E {L ( (0))} < ∞. Under the proposed optimization algorithm for task generation and computation offloading, the virtual queue is mean rate stable.

2) AVERAGE WEIGHTED-SUM UTILITY PERFORMANCE
Here, we show that the proposed algorithm is asymptotically optimal and give the average weighted-sum utility performance under the proposed algorithm by Theorem 2. Theorem 2: Under the proposed algorithm, the gap between the average weighted-sum utility and the optimal value is less than within B/V .
In practice, it is difficult to obtain the optimal solution of the formulated problem (P1) with complex constraints. Theorem 2 shows that an asymptotically optimal solution can be obtained by controlling the parameter V . In other words, when V increases to a certain value, the system utility (i.e., the average weighted-sum age at all devices) will approach the optimal value, which is more realistic than obtaining the optimal value with high complexity.

VI. SIMULATION RESULTS
In this section, we evaluate the stability of virtual queue and the tradeoff between the average per-device age and the average per-device energy consumption. Then we compare the average per-device age obtained by four different status update schemes: proposed scheme, age-based status update with local computing only scheme, age-based status update with offloading only scheme and age-based status update with random offloading scheme. We find out that the average virtual queue backlog stabilizes over time, and the proposed scheme outperforms the local computing only scheme, the offloading only scheme and the random offloading scheme in terms of average per-device age.

A. SIMULATION SETTING
The parameters are set as follows unless stated otherwise. The input size of each task is C = 5000 bits and the length of the time slot is τ = 200 ms. For local computing, ξ = 10 −28 and the required CPU cycles for processing 1 bit data is w = 2.5 × 10 5 cycles/bit [13]. For offloading, the uplink channel state of each device in each time slot is generated randomly according to the probability distribution p H , where the uplink channel states of each device is set to H = {0.0131, 0.0418, 0.0753, 0.1157, 0.1661, 0.2343, 0.3407, 0.6200} and the corresponding probabilities are p H = [1, 1, 2, 3 , 3, 2, 1, 1] 14 [34], [40]. The subchannel bandwidth is W = 32 kHz. Moreover, the available computational resources at the MEC server and the number of available subchannels are F (t) ∼ U [50, 250] GHz and K (t) ∼ U [5,25] Fig.4 shows the curves of average per-device age with different average energy thresholds (E th ) under the proposed scheme as V increases from 0.01 to 8. As shown in Fig.4, the average age decreases at the rate of O 1 V , which affirms the conclusion of Theorem 2. In particular, the average age decreases rapidly as V increases when V ≤ 1 and then decreases slowly until it starts to stabilize when V ≥ 3. This is because that a larger V implies that the system emphasizes the utility more. Therefore, as V increases, the average utility increases, which leads to the decrease in the average age. In addition, we also observe that a larger average energy threshold leads to a smaller average age. The reason is that  when the energy budget of each device increases, the number of obtained status updates increases, which results in the decrease in the average age. Fig.5 shows the curves of average per-device energy consumption with different average energy thresholds (E th ) under the proposed scheme as V increases from 0.01 to 8. It can be observed that the average energy consumption increases rapidly as V increases when V ≤ 1 and then increases slowly until it starts to stabilize when V ≥ 3. Because when V increases, the system emphasizes the utility more, which requires end devices to consume more energy to obtain more status updates, and thereby get more utility.

D. PERFORMANCE EVALUATION
We compare the average per-device age obtained by four different schemes: proposed scheme, local computing only scheme, offloading only scheme, and random offloading scheme. Fig. 6 shows the trend of average age obtained by these four schemes under different input-bits of task (C) as the number of devices increases from 40 to 200. As shown in Fig. 6, as the number of devices increases, the average age obtained by proposed scheme and random offloading scheme increases slowly; the average age obtained by offloading only scheme increases linearly; the average age obtained by local computing only scheme remains the same. It is easy to observe that the proposed scheme outperforms the local computing only scheme, the offloading only scheme, and the random offloading scheme in terms of the average age for a given C. This is because that on the one hand, the chances of computational resources at MEC servers and wireless subchannels being used become lower with more devices, which results in more devices not obtaining status updates under the offloading only scheme. On the other hand, as for the local computing only scheme, the device only obtains status updates by locally executing tasks, which consumes more energy. Moreover, for the random offloading scheme, the AP randomly selects devices from the devices in case (b) and case (e) and allows them to offload tasks without considering the timeliness of obtained status updates and the energy consumption of offloading tasks. For the proposed scheme, the device consumes less energy by offloading tasks to the MEC server for executing by using the available computational resources at MEC servers and subchannels under the good channel state. In addition, the device can also obtain status updates by locally executing tasks under the bad channel state and the few available computational resources and subchannels. Then, we have that a larger C leads to a larger average age from Fig. 6(a) and Fig. 6(b). Because when C increases, the resources (i.e., the energy of device and the computational resource at MEC servers) required to executing each task increase, which leads to the decrease in the number of obtained status updates under a given amount of resources. Fig. 7 shows the curves of average per-device age with different maximum CPU resources (F max ) under four different schemes: proposed scheme, local computing only scheme, offloading only scheme, and random offloading scheme when the maximum number of subchannels (K max ) increases from 5 to 65. As shown in Fig. 7, we observe that as K max increases, the average age obtained by proposed scheme, offloading only scheme and random offloading scheme first decreases and then stabilizes, and the average age obtained by local computing only scheme remains the same. This is because that when K max increases, more devices can obtain status updates by offloading tasks to the MEC server VOLUME 8, 2020 for executing. However, when K max increases to a certain value, the task offloading will no longer be limited by the number of available subchannels, and thus the average age will remain unchanged. Moreover, for the local computing only scheme, the status update decision of each device is not affected by the number of available subchannels. Then, from Fig. 7(a) and Fig. 7(b), we also observe that a larger F max results in a smaller average age under the proposed scheme, offloading only scheme and random offloading scheme, and the average age obtained by the local computing only remains the same regardless of CPU resources. The reason is that more CPU resources at MEC servers allow more devices to offload tasks to the MEC server for executing, and thus more status updates are obtained under given other resource constraints.   8 shows the curves of average per-device age with different required cycles for processing 1 bit data (w) under four different schemes: proposed scheme, local computing only scheme, offloading only scheme, and random offloading scheme when the maximum CPU resource (F max ) increases from 50 GHz to 350 GHz. As shown in Fig. 8, when F max increases, the average age obtained by proposed scheme, offloading only scheme, and random offloading scheme first decreases and then stabilizes, and the average age obtained by local computing only scheme remains the same. Because as F max increases, more devices can obtain status updates by offloading tasks to the MEC server for executing. However, when F max increases to a certain value, the task offloading will no longer be limited by the available CPU resources at MEC servers, and thus the average age will remain unchanged. Moreover, under the local computing only scheme, the devices only can obtain status updates by locally executing tasks and the available CPU resources at MEC servers do not affect the status update decision of each device. Then, we observe that more required cycles for processing 1 bit data result in a larger average age from Fig. 8(a) and Fig. 8(b). This is because that when the required cycles for processing 1 bit data increase, the energy consumption caused by locally executing each task and the CPU resources required to execute each task at MEC servers both increase, which leads to the decrease in the number of obtained status updates under the given resource constraints.

VII. CONCLUSION
In this paper, we investigated a stochastic control problem of task generation and computation offloading to minimize the average age of obtained status updates at all devices under the average energy constraint at each device, the timevarying wireless channel, as well as the limited and stochastic computational resources at MEC servers. To solve the longterm stochastic optimization problem, we transformed the average energy constraint at each device into a queue stability problem, and by leveraging the Lyapunov optimization technique, converted this stochastic optimization problem to the deterministic optimization in each time slot with the asymptotic optimality. Then, we formulated the deterministic optimization in each time slot as a knapsack problem and proposed an online optimization algorithm to make the decisions of task generation and computation offloading according to the current network state. Moreover, we analyzed the stability of virtual queue and proved that the proposed scheme achieved the close-to-optimal performance. Simulation results showed that the proposed scheme performed better than existing schemes in terms of obtaining status updates in a timely manner. For further work, we will investigate the timeliness of status updates obtained by executing computation tasks in distributed wireless networks without central coordination.

APPENDIXES APPENDIX A PROOF OF LEMMA 1
If Z i (t) is mean rate stable, we have lim t→∞ E{|Z i (t)|} t = 0. Summing (17) over t ∈ {0, 1, 2, · · · , T − 1}, we have and then have Taking the expectation of (29) and the limit as T → ∞, we can obtain that Therefore, we have E i ≤ E th i , i ∈ M.

APPENDIX B PROOF OF LEMMA 2
Note that for any a, b, c ≥ 0, the following inequality In addition, due to (T − t − 1) ≥ 1, we have Substituting (32) and (33)  First, under a feasible stationary policy, we have where E * i (t) and ϕ * i (t) are corresponding values under the feasible stationary policy. Substituting (25) and (26) into (35) and taking the limit as σ → 0, we have VOLUME 8, 2020 Summing (36) from t = 0 to T − 1, we have Then, we rearrange (37) and for all i ∈ M have where ϕ max is finite constant and ϕ ≤ ϕ max . Moreover, based Dividing (39) by T and taking the limit as T → ∞ Therefore, we have that the virtual queue is mean rate stable, thus completing the proof.

APPENDIX D PROOF OF THEOREM 2
According to the inequality (37), we have Dividing (41) by VT and taking the limit as T → ∞, we have ϕ opt − ϕ ≤ B V , thus completing the proof.