Skip to content

Commit

Permalink
Merge pull request #1219 from trapexit/fuse-config
Browse files Browse the repository at this point in the history
Move fuse thread args out of fuse session object
  • Loading branch information
trapexit authored Jul 31, 2023
2 parents 539f222 + 51d97bb commit 282ce08
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 89 deletions.
4 changes: 2 additions & 2 deletions libfuse/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ SRC_C = \
lib/fuse.c \
lib/fuse_dirents.c \
lib/fuse_lowlevel.c \
lib/fuse_mt.c \
lib/node.c \
lib/fuse_node.c \
lib/fuse_opt.c \
Expand All @@ -57,7 +56,8 @@ SRC_CPP = \
lib/format.cpp \
lib/os.cpp \
lib/cpu.cpp \
lib/fuse_loop_mt.cpp \
lib/fuse_config.cpp \
lib/fuse_loop.cpp \
lib/fuse_msgbuf.cpp
OBJS_C = $(SRC_C:lib/%.c=build/%.o)
OBJS_CPP = $(SRC_CPP:lib/%.cpp=build/%.o)
Expand Down
31 changes: 31 additions & 0 deletions libfuse/include/fuse_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
ISC License
Copyright (c) 2023, Antonio SJ Musumeci <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#pragma once

#include <string>

int fuse_config_get_read_thread_count();
int fuse_config_get_process_thread_count();
int fuse_config_get_process_thread_queue_depth();
std::string fuse_config_get_pin_threads();

void fuse_config_set_read_thread_count(int const);
void fuse_config_set_process_thread_count(int const);
void fuse_config_set_process_thread_queue_depth(int const);
void fuse_config_set_pin_threads(std::string const);
34 changes: 0 additions & 34 deletions libfuse/lib/fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ struct fuse_config
int set_uid;
int set_gid;
int help;
int read_thread_count;
int process_thread_count;
int process_thread_queue_depth;
char *pin_threads;
};

struct fuse_fs
Expand Down Expand Up @@ -3601,11 +3597,6 @@ static const struct fuse_opt fuse_lib_opts[] =
FUSE_LIB_OPT("gid=%d", gid,0),
FUSE_LIB_OPT("noforget", remember,-1),
FUSE_LIB_OPT("remember=%u", remember,0),
FUSE_LIB_OPT("threads=%d", read_thread_count,0),
FUSE_LIB_OPT("read-thread-count=%d", read_thread_count,0),
FUSE_LIB_OPT("process-thread-count=%d", process_thread_count,-1),
FUSE_LIB_OPT("process-thread-queue-depth=%d", process_thread_queue_depth,-1),
FUSE_LIB_OPT("pin-threads=%s", pin_threads, 0),
FUSE_OPT_END
};

Expand Down Expand Up @@ -4044,31 +4035,6 @@ fuse_destroy(struct fuse *f)
fuse_delete_context_key();
}

int
fuse_config_read_thread_count(const struct fuse *f_)
{
return f_->conf.read_thread_count;
}

int
fuse_config_process_thread_count(const struct fuse *f_)
{
return f_->conf.process_thread_count;
}

int
fuse_config_process_thread_queue_depth(const struct fuse *f_)
{
return f_->conf.process_thread_queue_depth;
}

const
char*
fuse_config_pin_threads(const struct fuse *f_)
{
return f_->conf.pin_threads;
}

void
fuse_log_metrics_set(int log_)
{
Expand Down
73 changes: 73 additions & 0 deletions libfuse/lib/fuse_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
ISC License
Copyright (c) 2023, Antonio SJ Musumeci <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <string>

static int g_READ_THREAD_COUNT = -1;
static int g_PROCESS_THREAD_COUNT = -1;
static int g_PROCESS_THREAD_QUEUE_DEPTH = -1;
static std::string g_PIN_THREADS = {};


int
fuse_config_get_read_thread_count()
{
return g_READ_THREAD_COUNT;
}

void
fuse_config_set_read_thread_count(int const v_)
{
g_READ_THREAD_COUNT = v_;
}

int
fuse_config_get_process_thread_count()
{
return g_PROCESS_THREAD_COUNT;
}

void
fuse_config_set_process_thread_count(int const v_)
{
g_PROCESS_THREAD_COUNT = v_;
}

int
fuse_config_get_process_thread_queue_depth()
{
return g_PROCESS_THREAD_QUEUE_DEPTH;
}

void
fuse_config_set_process_thread_queue_depth(int const v_)
{
g_PROCESS_THREAD_QUEUE_DEPTH = v_;
}

std::string
fuse_config_get_pin_threads()
{
return g_PIN_THREADS;
}

void
fuse_config_set_pin_threads(std::string const v_)
{
g_PIN_THREADS = v_;
}
46 changes: 38 additions & 8 deletions libfuse/lib/fuse_loop_mt.cpp → libfuse/lib/fuse_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "fuse_lowlevel.h"
#include "fuse_misc.h"

#include "fuse_config.hpp"
#include "fuse_msgbuf.hpp"
#include "fuse_ll.hpp"

Expand Down Expand Up @@ -418,10 +419,12 @@ pin_threads_R1PPSP(const std::vector<pthread_t> read_threads_,

static
void
pin_threads(const std::vector<pthread_t> read_threads_,
const std::vector<pthread_t> process_threads_,
const std::string type_)
pin_threads(const std::vector<pthread_t> read_threads_,
const std::vector<pthread_t> process_threads_,
const std::string type_)
{
if(type_.empty())
return;
if(type_ == "R1L")
return ::pin_threads_R1L(read_threads_);
if(type_ == "R1P")
Expand All @@ -440,6 +443,8 @@ pin_threads(const std::vector<pthread_t> read_threads_,
return ::pin_threads_RPSP(read_threads_,process_threads_);
if(type_ == "R1PPSP")
return ::pin_threads_R1PPSP(read_threads_,process_threads_);

syslog_warning("Invalid pin-threads value, ignoring: %s",type_.c_str());
}

static
Expand All @@ -456,7 +461,7 @@ fuse_session_loop_mt(struct fuse_session *se_,
const int raw_read_thread_count_,
const int raw_process_thread_count_,
const int raw_process_thread_queue_depth_,
const char *pin_threads_type_)
const std::string pin_threads_type_)
{
sem_t finished;
int read_thread_count;
Expand Down Expand Up @@ -496,17 +501,42 @@ fuse_session_loop_mt(struct fuse_session *se_,
if(process_tp)
process_threads = process_tp->threads();

if(pin_threads_type_ != nullptr)
::pin_threads(read_threads,process_threads,pin_threads_type_);
::pin_threads(read_threads,process_threads,pin_threads_type_);

syslog_info("read-thread-count=%d; process-thread-count=%d; process-thread-queue-depth=%d",
syslog_info("read-thread-count=%d; "
"process-thread-count=%d; "
"process-thread-queue-depth=%d; "
"pin-threads=%s;"
,
read_thread_count,
process_thread_count,
process_thread_queue_depth);
process_thread_queue_depth,
pin_threads_type_);

::wait(se_,&finished);

sem_destroy(&finished);

return 0;
}

int
fuse_loop_mt(struct fuse *f)
{
if(f == NULL)
return -1;

int res = fuse_start_maintenance_thread(f);
if(res)
return -1;

res = fuse_session_loop_mt(fuse_get_session(f),
fuse_config_get_read_thread_count(),
fuse_config_get_process_thread_count(),
fuse_config_get_process_thread_queue_depth(),
fuse_config_get_pin_threads());

fuse_stop_maintenance_thread(f);

return res;
}
38 changes: 0 additions & 38 deletions libfuse/lib/fuse_mt.c

This file was deleted.

14 changes: 7 additions & 7 deletions src/option_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "version.hpp"

#include "fuse.h"
#include "fuse_config.hpp"

#include <fstream>
#include <iomanip>
Expand Down Expand Up @@ -77,13 +78,12 @@ set_kv_option(const std::string &key_,

static
void
set_fuse_threads(Config::Write &cfg_,
fuse_args *args_)
set_fuse_threads(Config::Write &cfg_)
{
set_kv_option("read-thread-count",cfg_->fuse_read_thread_count.to_string(),args_);
set_kv_option("process-thread-count",cfg_->fuse_process_thread_count.to_string(),args_);
set_kv_option("process-thread-queue-depth",cfg_->fuse_process_thread_queue_depth.to_string(),args_);
set_kv_option("pin-threads",cfg_->fuse_pin_threads.to_string(),args_);
fuse_config_set_read_thread_count(cfg_->fuse_read_thread_count);
fuse_config_set_process_thread_count(cfg_->fuse_process_thread_count);
fuse_config_set_process_thread_queue_depth(cfg_->fuse_process_thread_queue_depth);
fuse_config_set_pin_threads(cfg_->fuse_pin_threads);
}

static
Expand Down Expand Up @@ -447,7 +447,7 @@ namespace options
set_default_options(args_);
set_fsname(cfg,args_);
set_subtype(args_);
set_fuse_threads(cfg,args_);
set_fuse_threads(cfg);

cfg->finish_initializing();
}
Expand Down

0 comments on commit 282ce08

Please sign in to comment.