* Copyright (c) 2020 Huawei Technologies Co.,Ltd.
*
* openGauss is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* ---------------------------------------------------------------------------------------
*
* ioschdl.h
* definitions for IO control parameters
*
* IDENTIFICATION
* src/include/workload/ioschdl.h
*
* ---------------------------------------------------------------------------------------
*/
#ifndef IOSCHDL_H
#define IOSCHDL_H
#include "postgres.h"
#include "knl/knl_variable.h"
#define IO_TYPE_WRITE 0
#define IO_TYPE_READ 1
#define IO_TYPE_COLUMN 0
#define IO_TYPE_ROW 1
#define MAX_DEVICE_DIR 256
#define UTIL_COUNT_LEN 3
#define UTIL_HIGH_THRESHOLD 50
#define UTIL_LOW_THRESHOLD 30
#define UTIL_LOW 0
#define UTIL_MEDIUM 1
#define UTIL_HIGH 2
#define FETCH_IOSTAT 0
#define RESET_IOSTAT 1
#define IO_MIN_COST 50000
#define IOCONTROL_UNIT 6000
#define W_RATIO_THRESHOLD 30
#define IOPS_LOW_LIMIT 5
#define FULL_PERCENT 100
#define IOPRIORITY_NONE 0
#define IOPRIORITY_LOW 10
#define IOPRIORITY_MEDIUM 20
#define IOPRIORITY_HIGH 50
#define WLM_AUTOWAKE_INTERVAL 1
#define IOLIMIT_WAKE_TIME 1
#define CPUSTAT_WAKE_TIME 8
#define IOPRIORITY_LOW_WAKE_TIME 3
#define IOPRIORITY_MEDIUM_WAKE_TIME 2
#define IOPRIORITY_HIGH_WAKE_TIME 1
#define FILE_DISKSTAT "/proc/diskstats"
#define FILE_CPUSTAT "/proc/stat"
#define FILE_MOUNTS "/proc/mounts"
#define AVERAGE_DISK_VALUE(m, n, p, u) (((double)((n) - (m))) / (p)*u)
typedef struct IORequestEntry {
int amount;
int rqst_type;
int count;
int count_down;
pthread_cond_t io_proceed_cond;
} IORequestEntry;
struct blkio_info {
int used;
uint64 rd_ios;
uint64 wr_ios;
uint64 rd_sectors;
uint64 wr_sectors;
uint64 tot_ticks;
};
typedef struct WLMmonitor_iostat {
char device[MAX_DEVICE_DIR];
double rs;
double ws;
double util;
double w_ratio;
double cpu_util;
int cpu_util_count;
int cpu_count;
unsigned char device_util_tbl[UTIL_COUNT_LEN];
int total_tbl_util;
int tick_count;
int maxIOUtil;
int minIOUtil;
int maxCpuUtil;
int minCpuUtil;
int node_count;
} WLMmonitor_iostat;
typedef struct WLMIOContext {
List* waiting_list;
pthread_mutex_t waiting_list_mutex;
int cpu_nr;
* cpu total time calculated from /proc/stat,
* the first element stores the last one,
* and the second stores the current
*/
uint64 uptime[2];
uint64 uptime0[2];
uint64 cputime_user[2];
TimestampTz prev_timestamp;
TimestampTz cur_timestamp;
uint32 hz;
struct blkio_info new_blkio;
struct blkio_info old_blkio;
WLMmonitor_iostat WLMmonitorDeviceStat;
bool device_init;
} WLMIOContext;
extern void IOStatistics(int type, int count, int size);
extern void IOSchedulerAndUpdate(int type, int count, int store_type);
extern void WLMmonitor_check_and_update_IOCost(PlannerInfo* root, NodeTag node, Cost IOcost);
extern ThreadId StartWLMmonitor(void);
extern ThreadId StartWLMarbiter(void);
#ifdef EXEC_BACKEND
extern void WLMmonitorMain();
extern void WLMarbiterMain();
#endif
#endif