From 4942189cf7b1a45b23d62f4ae92a940721ec4009 Mon Sep 17 00:00:00 2001
From: Yuri Victorovich <yuri@FreeBSD.org>
Date: Sat, 4 Dec 2021 18:25:00 -0800
Subject: [PATCH] FreeBSD compatibility patches.

---
 extras/usd/examples/usdObj/pch.h              |  2 +-
 extras/usd/examples/usdSchemaExamples/pch.h   |  2 +-
 pxr/base/arch/assumptions.cpp                 |  4 ++
 pxr/base/arch/daemon.cpp                      |  2 +-
 pxr/base/arch/debugger.cpp                    | 15 ++--
 pxr/base/arch/defines.h                       |  6 +-
 pxr/base/arch/fileSystem.cpp                  | 69 +++++++++++++++++--
 pxr/base/arch/fileSystem.h                    |  4 +-
 pxr/base/arch/mallocHook.cpp                  |  2 +-
 pxr/base/arch/math.h                          |  2 +-
 pxr/base/arch/pch.h                           |  2 +-
 pxr/base/arch/stackTrace.cpp                  |  8 +--
 pxr/base/arch/symbols.cpp                     |  2 +-
 pxr/base/arch/systemInfo.cpp                  | 20 ++++--
 pxr/base/arch/timing.cpp                      | 22 ++++++
 pxr/base/arch/timing.h                        |  2 +-
 pxr/base/plug/pch.h                           |  2 +-
 pxr/base/tf/fileUtils.cpp                     |  2 +-
 pxr/base/tf/pch.h                             |  2 +-
 pxr/base/tf/testenv/mallocTag.cpp             |  2 +-
 pxr/base/trace/pch.h                          |  2 +-
 pxr/base/vt/pch.h                             |  2 +-
 pxr/base/work/pch.h                           |  2 +-
 pxr/imaging/garch/glDebugWindow.cpp           |  2 +-
 pxr/imaging/garch/glPlatformContext.h         |  2 +-
 pxr/imaging/garch/glPlatformDebugContext.cpp  |  2 +-
 pxr/imaging/garch/pch.h                       |  2 +-
 pxr/imaging/glf/pch.h                         |  2 +-
 pxr/imaging/hd/pch.h                          |  2 +-
 pxr/imaging/hdMtlx/pch.h                      |  2 +-
 pxr/imaging/hdSt/pch.h                        |  2 +-
 pxr/imaging/hdx/pch.h                         |  2 +-
 pxr/imaging/hgi/hgi.cpp                       |  2 +-
 pxr/imaging/hgiGL/pch.h                       |  2 +-
 pxr/imaging/hgiMetal/pch.h                    |  2 +-
 pxr/imaging/hgiVulkan/pch.h                   |  2 +-
 pxr/imaging/hio/pch.h                         |  2 +-
 pxr/imaging/hioOpenVDB/pch.h                  |  2 +-
 pxr/imaging/plugin/hdEmbree/pch.h             |  2 +-
 .../plugin/hdPrmanLoader/rendererPlugin.cpp   |  6 +-
 pxr/imaging/plugin/hdStorm/pch.h              |  2 +-
 pxr/imaging/plugin/hioOiio/pch.h              |  2 +-
 pxr/imaging/pxOsd/pch.h                       |  2 +-
 pxr/usd/ar/pch.h                              |  2 +-
 pxr/usd/ndr/pch.h                             |  2 +-
 pxr/usd/pcp/pch.h                             |  2 +-
 pxr/usd/plugin/sdrOsl/pch.h                   |  2 +-
 pxr/usd/plugin/usdAbc/pch.h                   |  2 +-
 pxr/usd/plugin/usdDraco/pch.h                 |  2 +-
 pxr/usd/plugin/usdMtlx/pch.h                  |  2 +-
 pxr/usd/sdf/pch.h                             |  2 +-
 pxr/usd/sdr/pch.h                             |  2 +-
 pxr/usd/usd/pch.h                             |  2 +-
 pxr/usd/usdGeom/pch.h                         |  2 +-
 pxr/usd/usdHydra/pch.h                        |  2 +-
 pxr/usd/usdLux/pch.h                          |  2 +-
 pxr/usd/usdMedia/pch.h                        |  2 +-
 pxr/usd/usdPhysics/pch.h                      |  2 +-
 pxr/usd/usdRender/pch.h                       |  2 +-
 pxr/usd/usdRi/pch.h                           |  2 +-
 pxr/usd/usdShade/pch.h                        |  2 +-
 pxr/usd/usdSkel/pch.h                         |  2 +-
 pxr/usd/usdUI/pch.h                           |  2 +-
 pxr/usd/usdUtils/pch.h                        |  2 +-
 pxr/usd/usdVol/pch.h                          |  2 +-
 pxr/usdImaging/plugin/usdShaders/pch.h        |  2 +-
 pxr/usdImaging/usdAppUtils/pch.h              |  2 +-
 pxr/usdImaging/usdImaging/pch.h               |  2 +-
 pxr/usdImaging/usdImagingGL/pch.h             |  2 +-
 pxr/usdImaging/usdRiImaging/pch.h             |  2 +-
 pxr/usdImaging/usdSkelImaging/pch.h           |  2 +-
 pxr/usdImaging/usdVolImaging/pch.h            |  2 +-
 pxr/usdImaging/usdviewq/pch.h                 |  2 +-
 .../renderman-24/plugin/rmanArgsParser/pch.h  |  2 +-
 74 files changed, 189 insertions(+), 95 deletions(-)

diff --git a/extras/usd/examples/usdObj/pch.h b/extras/usd/examples/usdObj/pch.h
index 6a8744cbc7..f34d309e3a 100644
--- a/extras/usd/examples/usdObj/pch.h
+++ b/extras/usd/examples/usdObj/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/extras/usd/examples/usdSchemaExamples/pch.h b/extras/usd/examples/usdSchemaExamples/pch.h
index 47666439a2..3077d93203 100644
--- a/extras/usd/examples/usdSchemaExamples/pch.h
+++ b/extras/usd/examples/usdSchemaExamples/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/base/arch/assumptions.cpp b/pxr/base/arch/assumptions.cpp
index 69d6d13f72..35bec1db16 100644
--- a/pxr/base/arch/assumptions.cpp
+++ b/pxr/base/arch/assumptions.cpp
@@ -35,6 +35,8 @@
 
 #if defined(ARCH_OS_LINUX)
 #include <unistd.h>
+#elif defined(ARCH_OS_FREEBSD)
+#include <sys/param.h>
 #elif defined(ARCH_OS_DARWIN)
 #include <sys/sysctl.h>
 #include <mach-o/arch.h>
@@ -50,6 +52,8 @@ Arch_ObtainCacheLineSize()
 {
 #if defined(ARCH_OS_LINUX)
     return sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+#elif defined(ARCH_OS_FREEBSD)
+    return CACHE_LINE_SIZE;
 #elif defined(ARCH_OS_DARWIN)
     size_t cacheLineSize = 0;
     size_t cacheLineSizeSize = sizeof(cacheLineSize);
diff --git a/pxr/base/arch/daemon.cpp b/pxr/base/arch/daemon.cpp
index 33cf10de06..752dc0c0de 100644
--- a/pxr/base/arch/daemon.cpp
+++ b/pxr/base/arch/daemon.cpp
@@ -45,7 +45,7 @@ PXR_NAMESPACE_OPEN_SCOPE
 int
 ArchCloseAllFiles(int nExcept, const int* exceptFds)
 {
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
 
     int status, retStatus, retErrno;
     int i, j, maxfd, maxExcept = -1;
diff --git a/pxr/base/arch/debugger.cpp b/pxr/base/arch/debugger.cpp
index fd093f09e9..cb74a3cda1 100644
--- a/pxr/base/arch/debugger.cpp
+++ b/pxr/base/arch/debugger.cpp
@@ -31,7 +31,7 @@
 #include "pxr/base/arch/export.h"
 #include "pxr/base/arch/stackTrace.h"
 #include "pxr/base/arch/systemInfo.h"
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
 #include "pxr/base/arch/inttypes.h"
 #include <sys/types.h>
 #include <sys/ptrace.h>
@@ -46,6 +46,7 @@
 #include <unistd.h>
 #include <string>
 #endif
+#include <signal.h>
 #if defined(ARCH_OS_DARWIN)
 #include <sys/sysctl.h>
 #endif
@@ -67,7 +68,7 @@ static std::atomic<bool> _archDebuggerWait(false);
 
 static char** _archDebuggerAttachArgs = 0;
 
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
 static
 void
 Arch_DebuggerTrapHandler(int)
@@ -82,7 +83,7 @@ Arch_DebuggerTrapHandler(int)
 }
 #endif
 
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
 static
 void
 Arch_DebuggerInitPosix()
@@ -116,7 +117,7 @@ static
 void
 Arch_DebuggerInit()
 {
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
 #if defined(ARCH_CPU_INTEL) && defined(ARCH_BITS_64)
     // Save some registers that normally don't have to be preserved.  We
     // do this so the caller of ArchDebuggerTrap() can see its arguments
@@ -161,7 +162,7 @@ Arch_DebuggerInit()
 }
 
 
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
 // Use a 'non-locking' fork so that we won't get hung up if we've
 // had malloc corruption.  We can't prevent fork() from using the
 // heap, unfortunately, since fork handlers can do whatever they
@@ -440,7 +441,7 @@ Arch_DebuggerAttach()
         return false;
     }
 
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
 
     // To attach to gdb under Unix/Linux and Gnome:
     //   ARCH_DEBUGGER="gnome-terminal -e 'gdb -p %p'"
@@ -497,7 +498,7 @@ ARCH_HIDDEN
 void
 Arch_InitDebuggerAttach()
 {
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
     // Maximum length of a pid written as a decimal.  It's okay for this
     // to be greater than that.
     static const size_t _decimalPidLength = 20;
diff --git a/pxr/base/arch/defines.h b/pxr/base/arch/defines.h
index b8efcd8244..858657d0f2 100644
--- a/pxr/base/arch/defines.h
+++ b/pxr/base/arch/defines.h
@@ -34,6 +34,8 @@ PXR_NAMESPACE_OPEN_SCOPE
 
 #if defined(__linux__)
 #define ARCH_OS_LINUX
+#elif defined(__FreeBSD__)
+#define ARCH_OS_FREEBSD
 #elif defined(__APPLE__)
 #include "TargetConditionals.h"
 #define ARCH_OS_DARWIN
@@ -93,7 +95,7 @@ PXR_NAMESPACE_OPEN_SCOPE
 //
 
 // Only use the GNU STL extensions on Linux when using gcc.
-#if defined(ARCH_OS_LINUX) && defined(ARCH_COMPILER_GCC)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) && defined(ARCH_COMPILER_GCC)
 #define ARCH_HAS_GNU_STL_EXTENSIONS
 #endif
 
@@ -104,7 +106,7 @@ PXR_NAMESPACE_OPEN_SCOPE
 #endif
 
 // The MAP_POPULATE flag for mmap calls only exists on Linux platforms.
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #define ARCH_HAS_MMAP_MAP_POPULATE
 #endif
 
diff --git a/pxr/base/arch/fileSystem.cpp b/pxr/base/arch/fileSystem.cpp
index f236bcbea6..f6f7bee8b4 100644
--- a/pxr/base/arch/fileSystem.cpp
+++ b/pxr/base/arch/fileSystem.cpp
@@ -51,12 +51,24 @@
 #include <Windows.h>
 #include <WinIoCtl.h>
 #else
+#if !defined(ARCH_OS_FREEBSD)
 #include <alloca.h>
+#else
+#include <stdlib.h>
+#endif
 #include <sys/mman.h>
 #include <sys/file.h>
 #include <unistd.h>
 #endif
 
+#if defined(ARCH_OS_FREEBSD)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/user.h>
+#endif
+
 PXR_NAMESPACE_OPEN_SCOPE
 
 using std::pair;
@@ -92,7 +104,7 @@ int ArchRmDir(const char* path)
 bool
 ArchStatIsWritable(const ArchStatType *st)
 {
-#if defined(ARCH_OS_LINUX) || defined (ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined (ARCH_OS_DARWIN)
     if (st) {
         return (st->st_mode & S_IWOTH) || 
             ((getegid() == st->st_gid) && (st->st_mode & S_IWGRP)) ||
@@ -129,7 +141,7 @@ ArchGetModificationTime(const char* pathname, double* time)
 double
 ArchGetModificationTime(const ArchStatType& st)
 {
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
     return st.st_mtim.tv_sec + 1e-9*st.st_mtim.tv_nsec;
 #elif defined(ARCH_OS_DARWIN)
     return st.st_mtimespec.tv_sec + 1e-9*st.st_mtimespec.tv_nsec;
@@ -386,7 +398,7 @@ ArchGetStatMode(const char *pathname, int *mode)
 double
 ArchGetAccessTime(const struct stat& st)
 {
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
     return st.st_atim.tv_sec + 1e-9*st.st_atim.tv_nsec;
 #elif defined(ARCH_OS_DARWIN)
     return st.st_atimespec.tv_sec + 1e-9*st.st_atimespec.tv_nsec;
@@ -401,7 +413,7 @@ ArchGetAccessTime(const struct stat& st)
 double
 ArchGetStatusChangeTime(const struct stat& st)
 {
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
     return st.st_ctim.tv_sec + 1e-9*st.st_ctim.tv_nsec;
 #elif defined(ARCH_OS_DARWIN)
     return st.st_ctimespec.tv_sec + 1e-9*st.st_ctimespec.tv_nsec;
@@ -431,7 +443,7 @@ ArchGetFileLength(FILE *file)
 {
     if (!file)
         return -1;
-#if defined (ARCH_OS_LINUX) || defined (ARCH_OS_DARWIN)
+#if defined (ARCH_OS_LINUX) || defined (ARCH_OS_FREEBSD) || defined (ARCH_OS_DARWIN)
     struct stat buf;
     return fstat(fileno(file), &buf) < 0 ? -1 :
         static_cast<int64_t>(buf.st_size);
@@ -445,7 +457,7 @@ ArchGetFileLength(FILE *file)
 int64_t
 ArchGetFileLength(const char* fileName)
 {
-#if defined (ARCH_OS_LINUX) || defined (ARCH_OS_DARWIN)
+#if defined (ARCH_OS_LINUX) || defined (ARCH_OS_FREEBSD) || defined (ARCH_OS_DARWIN)
     struct stat buf;
     return stat(fileName, &buf) < 0 ? -1 : static_cast<int64_t>(buf.st_size);
 #elif defined (ARCH_OS_WINDOWS)
@@ -479,6 +491,48 @@ ArchGetFileName(FILE *file)
         result.assign(buf, buf + r);
     }
     return result;
+#elif defined (ARCH_OS_FREEBSD)
+    int mib[4];
+    size_t i, len;
+    char *buffer = NULL;
+    struct kinfo_file *kf;
+    string path;
+
+    mib[0] = CTL_KERN;
+    mib[1] = KERN_PROC;
+    mib[2] = KERN_PROC_FILEDESC;
+    mib[3] = getpid();
+    len = 0;
+    if (sysctl( mib, sizeof(mib)/sizeof(mib[0]), NULL, &len, NULL, 0 ))
+        goto end;
+    len *= 2;
+    buffer = (char*)malloc( len );
+    if (!buffer)
+        goto end;
+    if (sysctl( mib, sizeof(mib)/sizeof(mib[0]), buffer, &len, NULL, 0 ))
+        goto end;
+
+    for (i = 0; i < len; )
+    {
+        kf = (struct kinfo_file*) &buffer[i];
+        if (kf->kf_structsize == 0)
+            break;
+        i += kf->kf_structsize;
+
+        if (kf->kf_fd == fileno(file))
+        {
+            if (kf->kf_path[0])
+            {
+                path.resize(strlen(kf->kf_path) + 1);
+                sprintf(&path[0], "%s", kf->kf_path);
+            }
+            break;
+        }
+    }
+
+end:
+    free( buffer );
+    return path;
 #elif defined (ARCH_OS_DARWIN)
     string result;
     char buf[MAXPATHLEN];
@@ -862,6 +916,9 @@ ArchQueryMappedMemoryResidency(
 #if defined(ARCH_OS_LINUX)
     int ret = mincore(const_cast<void *>(addr), len, pageMap);
     return ret == 0;
+#elif defined(ARCH_OS_FREEBSD)
+    int ret = mincore(const_cast<const void *>(addr), len, (char *)(pageMap));
+    return ret == 0;
 #elif defined (ARCH_OS_DARWIN)
     // On darwin the addr param is 'caddr_t' and the vec param is 'char *'.
     int ret = mincore(
diff --git a/pxr/base/arch/fileSystem.h b/pxr/base/arch/fileSystem.h
index d0987ba66d..ec045d63c4 100644
--- a/pxr/base/arch/fileSystem.h
+++ b/pxr/base/arch/fileSystem.h
@@ -41,9 +41,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <unistd.h>
-#include <sys/statfs.h>
+//#include <sys/statfs.h>
 #include <glob.h>
 #elif defined(ARCH_OS_DARWIN)
 #include <unistd.h>
diff --git a/pxr/base/arch/mallocHook.cpp b/pxr/base/arch/mallocHook.cpp
index b68a31afb3..0109860b29 100644
--- a/pxr/base/arch/mallocHook.cpp
+++ b/pxr/base/arch/mallocHook.cpp
@@ -177,7 +177,7 @@ ArchMallocHook::IsInitialized()
        _underlyingMemalignFunc || _underlyingFreeFunc;
 }
 
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 template <typename T>
 static bool _GetSymbol(T* addr, const char* name, string* errMsg) {
     if (void* symbol = dlsym(RTLD_DEFAULT, name)) {
diff --git a/pxr/base/arch/math.h b/pxr/base/arch/math.h
index f4c8d93d7c..43c567ca77 100644
--- a/pxr/base/arch/math.h
+++ b/pxr/base/arch/math.h
@@ -101,7 +101,7 @@ inline double ArchBitPatternToDouble(uint64_t v) {
 #error Unknown system architecture.
 #endif
 
-#if defined(ARCH_OS_LINUX) || defined(doxygen)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(doxygen)
 
 /// Computes the sine and cosine of the specified value as a float.
 inline void ArchSinCosf(float v, float *s, float *c) { sincosf(v, s, c); }
diff --git a/pxr/base/arch/pch.h b/pxr/base/arch/pch.h
index e12a42b037..3a2e58fe32 100644
--- a/pxr/base/arch/pch.h
+++ b/pxr/base/arch/pch.h
@@ -44,7 +44,7 @@
 #include <mach-o/swap.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <csignal>
 #include <dlfcn.h>
 #include <glob.h>
diff --git a/pxr/base/arch/stackTrace.cpp b/pxr/base/arch/stackTrace.cpp
index 54f11a4128..c0c234b239 100644
--- a/pxr/base/arch/stackTrace.cpp
+++ b/pxr/base/arch/stackTrace.cpp
@@ -70,11 +70,11 @@
 /* Darwin/ppc did not do stack traces.  Darwin/i386 still 
    needs some work, this has been stubbed out for now.  */
 
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <ucontext.h>
 #endif
 
-#if defined(ARCH_OS_LINUX) && defined(ARCH_BITS_64)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) && defined(ARCH_BITS_64)
 #include <unwind.h>
 #endif
 
@@ -105,7 +105,7 @@ using namespace std;
 // total hack -- no idea if this will work if we die in malloc...
 typedef int (*ForkFunc)(void);
 ForkFunc Arch_nonLockingFork =
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
     (ForkFunc)dlsym(RTLD_NEXT, "__libc_fork");
 #elif defined(ARCH_OS_DARWIN)
     NULL;
@@ -576,7 +576,7 @@ nonLockingFork()
 }
 #endif
 
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 static int
 nonLockingLinux__execve (const char *file,
                          char *const argv[],
diff --git a/pxr/base/arch/symbols.cpp b/pxr/base/arch/symbols.cpp
index 2c6bf030c4..db37d14d42 100644
--- a/pxr/base/arch/symbols.cpp
+++ b/pxr/base/arch/symbols.cpp
@@ -26,7 +26,7 @@
 #include "pxr/base/arch/fileSystem.h"
 #include "pxr/base/arch/symbols.h"
 #include "pxr/base/arch/defines.h"
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <dlfcn.h>
 #elif defined(ARCH_OS_DARWIN)
 #include <dlfcn.h>
diff --git a/pxr/base/arch/systemInfo.cpp b/pxr/base/arch/systemInfo.cpp
index d667c43ec9..0160e1e785 100644
--- a/pxr/base/arch/systemInfo.cpp
+++ b/pxr/base/arch/systemInfo.cpp
@@ -32,7 +32,7 @@
 #include <functional>
 #include <limits>
 
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 
     #include <sys/types.h>
     #include <sys/stat.h>
@@ -113,16 +113,23 @@ _DynamicSizedRead(
 std::string
 ArchGetExecutablePath()
 {
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 
+#if defined(ARCH_OS_LINUX)
     // On Linux the executable path is retrieved from the /proc/self/exe
     // symlink.
+#define SELF_PATHNAME "/proc/self/exe";
+#else
+    // On FreeBSD the executable path is retrieved from the /proc/curproc/file
+    // symlink.
+#define SELF_PATHNAME "/proc/curproc/file"
+#endif
     return
         _DynamicSizedRead(ARCH_PATH_MAX,
             [](char* buffer, size_t* size) {
-                const ssize_t n = readlink("/proc/self/exe", buffer, *size);
+                const ssize_t n = readlink(SELF_PATHNAME, buffer, *size);
                 if (n == -1) {
-                    ARCH_WARNING("Unable to read /proc/self/exe to obtain "
+                    ARCH_WARNING("Unable to read " SELF_PATHNAME " to obtain "
                                  "executable path");
                     *size = std::numeric_limits<size_t>::max();
                     return false;
@@ -130,7 +137,7 @@ ArchGetExecutablePath()
                 else if (static_cast<size_t>(n) >= *size) {
                     // Find out how much space we need.
                     struct stat sb;
-                    if (lstat("/proc/self/exe", &sb) == 0) {
+                    if (lstat(SELF_PATHNAME, &sb) == 0) {
                         *size = sb.st_size + 1;
                     }
                     else {
@@ -144,6 +151,7 @@ ArchGetExecutablePath()
                     return true;
                 }
             });
+#undef SELF_PATHNAME
 
 #elif defined(ARCH_OS_DARWIN)
 
@@ -192,7 +200,7 @@ ArchGetExecutablePath()
 int
 ArchGetPageSize()
 {
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
     return sysconf(_SC_PAGE_SIZE);
 #elif defined(ARCH_OS_WINDOWS)
     SYSTEM_INFO info;
diff --git a/pxr/base/arch/timing.cpp b/pxr/base/arch/timing.cpp
index 8ec0cf7d68..c6239e5c7a 100644
--- a/pxr/base/arch/timing.cpp
+++ b/pxr/base/arch/timing.cpp
@@ -32,6 +32,9 @@
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
+#elif defined(ARCH_OS_FREEBSD)
+#include <sys/types.h>
+#include <sys/sysctl.h>
 #elif defined(ARCH_OS_WINDOWS)
 #include <Windows.h>
 #include <chrono>
@@ -142,6 +145,25 @@ Arch_InitTickTimer()
     Arch_NanosecondsPerTick = double(1e9) / double(cpuHz);
 #endif
 }
+#elif defined(ARCH_OS_FREEBSD)
+
+ARCH_HIDDEN
+void
+Arch_InitTickTimer()
+{
+#if defined(ARCH_CPU_ARM)
+    uint64_t counter_hz;
+    __asm __volatile("mrs	%0, CNTFRQ_EL0" : "=&r" (counter_hz));
+    Arch_NanosecondsPerTick = double(1e9) / double(counter_hz);
+#else
+    unsigned int freq;
+    size_t len = sizeof(freq);
+    if (sysctlbyname("dev.cpu.1.freq", &freq, &len, NULL, 0))
+        ARCH_ERROR("Cannot retrieve the sysctl value dev.cpu.1.freq");
+    Arch_NanosecondsPerTick = double(1e9) / double(freq*1000000);
+#endif
+}
+
 #elif defined(ARCH_OS_WINDOWS)
 
 ARCH_HIDDEN
diff --git a/pxr/base/arch/timing.h b/pxr/base/arch/timing.h
index 615bade031..8ad3e47dda 100644
--- a/pxr/base/arch/timing.h
+++ b/pxr/base/arch/timing.h
@@ -36,7 +36,7 @@
 /// \addtogroup group_arch_SystemFunctions
 ///@{
 
-#if defined(ARCH_OS_LINUX) && defined(ARCH_CPU_INTEL)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) && defined(ARCH_CPU_INTEL)
 #include <x86intrin.h>
 #elif defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
diff --git a/pxr/base/plug/pch.h b/pxr/base/plug/pch.h
index 98b6fc7825..a0430611e9 100644
--- a/pxr/base/plug/pch.h
+++ b/pxr/base/plug/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/base/tf/fileUtils.cpp b/pxr/base/tf/fileUtils.cpp
index 8b4d67da00..62e09006e9 100644
--- a/pxr/base/tf/fileUtils.cpp
+++ b/pxr/base/tf/fileUtils.cpp
@@ -209,7 +209,7 @@ TfIsLink(string const& path)
 bool
 TfIsWritable(string const& path)
 {
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
     // faccessat accounts for mount read-only status. For maintaining legacy
     // behavior, use faccessat instead of access so we can use the effective
     // UID instead of the real UID. 
diff --git a/pxr/base/tf/pch.h b/pxr/base/tf/pch.h
index 11cb840f30..5e1aff46de 100644
--- a/pxr/base/tf/pch.h
+++ b/pxr/base/tf/pch.h
@@ -39,7 +39,7 @@
 #include <boost/preprocessor/config/limits.hpp>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <dirent.h>
 #include <glob.h>
 #include <sys/param.h>
diff --git a/pxr/base/tf/testenv/mallocTag.cpp b/pxr/base/tf/testenv/mallocTag.cpp
index 9befe5b05e..97882cd1df 100644
--- a/pxr/base/tf/testenv/mallocTag.cpp
+++ b/pxr/base/tf/testenv/mallocTag.cpp
@@ -35,7 +35,7 @@ PXR_NAMESPACE_USING_DIRECTIVE
 
 // The TfMallocTag code depends upon the Linux memory allocator, ptmalloc3.
 // Turning this test off for any other platforms for now.
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 
 using std::vector;
 using std::string;
diff --git a/pxr/base/trace/pch.h b/pxr/base/trace/pch.h
index 25f4b5d6cf..7e354eb906 100644
--- a/pxr/base/trace/pch.h
+++ b/pxr/base/trace/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/base/vt/pch.h b/pxr/base/vt/pch.h
index 75f03bee27..2cff81492f 100644
--- a/pxr/base/vt/pch.h
+++ b/pxr/base/vt/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/base/work/pch.h b/pxr/base/work/pch.h
index 228b18d0d8..c1c22659e0 100644
--- a/pxr/base/work/pch.h
+++ b/pxr/base/work/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/garch/glDebugWindow.cpp b/pxr/imaging/garch/glDebugWindow.cpp
index 18c372cc86..f05e99f6c7 100644
--- a/pxr/imaging/garch/glDebugWindow.cpp
+++ b/pxr/imaging/garch/glDebugWindow.cpp
@@ -26,7 +26,7 @@
 #include "pxr/imaging/garch/glPlatformDebugContext.h"
 #include "pxr/base/arch/defines.h"
 
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include "pxr/imaging/garch/glPlatformDebugWindowGLX.h"
 #elif defined(ARCH_OS_DARWIN)
 #include "pxr/imaging/garch/glPlatformDebugWindowDarwin.h"
diff --git a/pxr/imaging/garch/glPlatformContext.h b/pxr/imaging/garch/glPlatformContext.h
index de864498e5..40b0e95305 100644
--- a/pxr/imaging/garch/glPlatformContext.h
+++ b/pxr/imaging/garch/glPlatformContext.h
@@ -32,7 +32,7 @@
 #include <cstddef>
 #include <functional>
 
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 
 #include "pxr/imaging/garch/glPlatformContextGLX.h"
 
diff --git a/pxr/imaging/garch/glPlatformDebugContext.cpp b/pxr/imaging/garch/glPlatformDebugContext.cpp
index 335cdf4175..18a3fdfc8b 100644
--- a/pxr/imaging/garch/glPlatformDebugContext.cpp
+++ b/pxr/imaging/garch/glPlatformDebugContext.cpp
@@ -51,7 +51,7 @@ GarchGLPlatformDebugContext::IsEnabledCoreProfile()
 PXR_NAMESPACE_CLOSE_SCOPE
 
 ////////////////////////////////////////////////////////////
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 
 #include <GL/glx.h>
 #include <GL/glxtokens.h>
diff --git a/pxr/imaging/garch/pch.h b/pxr/imaging/garch/pch.h
index 7ef3bd8afd..8700fce9f4 100644
--- a/pxr/imaging/garch/pch.h
+++ b/pxr/imaging/garch/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #include <X11/Xlib.h>
 #endif
diff --git a/pxr/imaging/glf/pch.h b/pxr/imaging/glf/pch.h
index 9a7e85a6c4..5e0f1de056 100644
--- a/pxr/imaging/glf/pch.h
+++ b/pxr/imaging/glf/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/imaging/hd/pch.h b/pxr/imaging/hd/pch.h
index 604861b7b1..be7f6db27e 100644
--- a/pxr/imaging/hd/pch.h
+++ b/pxr/imaging/hd/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/hdMtlx/pch.h b/pxr/imaging/hdMtlx/pch.h
index bf8ff6a368..ada6263445 100644
--- a/pxr/imaging/hdMtlx/pch.h
+++ b/pxr/imaging/hdMtlx/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/hdSt/pch.h b/pxr/imaging/hdSt/pch.h
index 196960f7b7..315e1b24cb 100644
--- a/pxr/imaging/hdSt/pch.h
+++ b/pxr/imaging/hdSt/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/hdx/pch.h b/pxr/imaging/hdx/pch.h
index 33ddb1b5da..090347f5da 100644
--- a/pxr/imaging/hdx/pch.h
+++ b/pxr/imaging/hdx/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/hgi/hgi.cpp b/pxr/imaging/hgi/hgi.cpp
index d7bcdaae58..751f81598f 100644
--- a/pxr/imaging/hgi/hgi.cpp
+++ b/pxr/imaging/hgi/hgi.cpp
@@ -65,7 +65,7 @@ _MakeNewPlatformDefaultHgi()
     PlugRegistry& plugReg = PlugRegistry::GetInstance();
 
     const char* hgiType = 
-        #if defined(ARCH_OS_LINUX)
+        #if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
             "HgiGL";
         #elif defined(ARCH_OS_DARWIN)
             "HgiMetal";
diff --git a/pxr/imaging/hgiGL/pch.h b/pxr/imaging/hgiGL/pch.h
index 46881e229b..f83b4ec2ed 100644
--- a/pxr/imaging/hgiGL/pch.h
+++ b/pxr/imaging/hgiGL/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/hgiMetal/pch.h b/pxr/imaging/hgiMetal/pch.h
index 877bc45ee5..a1acee70a9 100644
--- a/pxr/imaging/hgiMetal/pch.h
+++ b/pxr/imaging/hgiMetal/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/hgiVulkan/pch.h b/pxr/imaging/hgiVulkan/pch.h
index c6d867fae4..d6c459bf31 100644
--- a/pxr/imaging/hgiVulkan/pch.h
+++ b/pxr/imaging/hgiVulkan/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/hio/pch.h b/pxr/imaging/hio/pch.h
index f42afdc5fb..acdd0df4cb 100644
--- a/pxr/imaging/hio/pch.h
+++ b/pxr/imaging/hio/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/imaging/hioOpenVDB/pch.h b/pxr/imaging/hioOpenVDB/pch.h
index 2b950ebb47..15fb50f6ce 100644
--- a/pxr/imaging/hioOpenVDB/pch.h
+++ b/pxr/imaging/hioOpenVDB/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/plugin/hdEmbree/pch.h b/pxr/imaging/plugin/hdEmbree/pch.h
index 7710229804..2daed51fe6 100644
--- a/pxr/imaging/plugin/hdEmbree/pch.h
+++ b/pxr/imaging/plugin/hdEmbree/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/plugin/hdPrmanLoader/rendererPlugin.cpp b/pxr/imaging/plugin/hdPrmanLoader/rendererPlugin.cpp
index c00ccaf684..30e4772f85 100644
--- a/pxr/imaging/plugin/hdPrmanLoader/rendererPlugin.cpp
+++ b/pxr/imaging/plugin/hdPrmanLoader/rendererPlugin.cpp
@@ -47,7 +47,7 @@ static struct HdPrmanLoader
 {
     static void Load();
     ~HdPrmanLoader();
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
     void* libprman = nullptr;
 #endif
     void* hdPrman = nullptr;
@@ -71,7 +71,7 @@ HdPrmanLoader::Load()
         return;
     }
 
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
     // Open $RMANTREE/lib/libprman.so into the global namespace
     const std::string libprmanPath =
         TfStringCatPaths(rmantree, "lib/libprman" ARCH_LIBRARY_SUFFIX);
@@ -135,7 +135,7 @@ HdPrmanLoader::~HdPrmanLoader()
         ArchLibraryClose(hdPrman);
         hdPrman = nullptr;
     }
-#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD) || defined(ARCH_OS_DARWIN)
     if (libprman) {
         ArchLibraryClose(libprman);
         libprman = nullptr;
diff --git a/pxr/imaging/plugin/hdStorm/pch.h b/pxr/imaging/plugin/hdStorm/pch.h
index 33c5124a97..5af865217c 100644
--- a/pxr/imaging/plugin/hdStorm/pch.h
+++ b/pxr/imaging/plugin/hdStorm/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/imaging/plugin/hioOiio/pch.h b/pxr/imaging/plugin/hioOiio/pch.h
index 9a7e85a6c4..5e0f1de056 100644
--- a/pxr/imaging/plugin/hioOiio/pch.h
+++ b/pxr/imaging/plugin/hioOiio/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/imaging/pxOsd/pch.h b/pxr/imaging/pxOsd/pch.h
index c7bbe82037..8c4848ce36 100644
--- a/pxr/imaging/pxOsd/pch.h
+++ b/pxr/imaging/pxOsd/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/ar/pch.h b/pxr/usd/ar/pch.h
index b3333376f4..54abb20b53 100644
--- a/pxr/usd/ar/pch.h
+++ b/pxr/usd/ar/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/usd/ndr/pch.h b/pxr/usd/ndr/pch.h
index 897ad796bf..f00aa253ba 100644
--- a/pxr/usd/ndr/pch.h
+++ b/pxr/usd/ndr/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/usd/pcp/pch.h b/pxr/usd/pcp/pch.h
index a7180637dd..3925efd50f 100644
--- a/pxr/usd/pcp/pch.h
+++ b/pxr/usd/pcp/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/plugin/sdrOsl/pch.h b/pxr/usd/plugin/sdrOsl/pch.h
index f1a725cd6d..c662863419 100644
--- a/pxr/usd/plugin/sdrOsl/pch.h
+++ b/pxr/usd/plugin/sdrOsl/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/plugin/usdAbc/pch.h b/pxr/usd/plugin/usdAbc/pch.h
index f5c7e6fb6c..d076eb2cf4 100644
--- a/pxr/usd/plugin/usdAbc/pch.h
+++ b/pxr/usd/plugin/usdAbc/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/usd/plugin/usdDraco/pch.h b/pxr/usd/plugin/usdDraco/pch.h
index aff99924d4..3e83afd197 100644
--- a/pxr/usd/plugin/usdDraco/pch.h
+++ b/pxr/usd/plugin/usdDraco/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/plugin/usdMtlx/pch.h b/pxr/usd/plugin/usdMtlx/pch.h
index 5eba44e7ed..baef1d01df 100644
--- a/pxr/usd/plugin/usdMtlx/pch.h
+++ b/pxr/usd/plugin/usdMtlx/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/usd/sdf/pch.h b/pxr/usd/sdf/pch.h
index 0728ebe683..f9dbd9130f 100644
--- a/pxr/usd/sdf/pch.h
+++ b/pxr/usd/sdf/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/usd/sdr/pch.h b/pxr/usd/sdr/pch.h
index b4edc214fc..d8514a1e4d 100644
--- a/pxr/usd/sdr/pch.h
+++ b/pxr/usd/sdr/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usd/pch.h b/pxr/usd/usd/pch.h
index bd515aa438..fc838cb704 100644
--- a/pxr/usd/usd/pch.h
+++ b/pxr/usd/usd/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/usd/usdGeom/pch.h b/pxr/usd/usdGeom/pch.h
index 824c5b0f93..0b0bfb6d12 100644
--- a/pxr/usd/usdGeom/pch.h
+++ b/pxr/usd/usdGeom/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usdHydra/pch.h b/pxr/usd/usdHydra/pch.h
index 5ba9df4c20..18305679cc 100644
--- a/pxr/usd/usdHydra/pch.h
+++ b/pxr/usd/usdHydra/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usdLux/pch.h b/pxr/usd/usdLux/pch.h
index 8fe34cb954..4944e897bc 100644
--- a/pxr/usd/usdLux/pch.h
+++ b/pxr/usd/usdLux/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usdMedia/pch.h b/pxr/usd/usdMedia/pch.h
index 7802ec3e2d..e4dfaad4e0 100644
--- a/pxr/usd/usdMedia/pch.h
+++ b/pxr/usd/usdMedia/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usdPhysics/pch.h b/pxr/usd/usdPhysics/pch.h
index 824c5b0f93..0b0bfb6d12 100644
--- a/pxr/usd/usdPhysics/pch.h
+++ b/pxr/usd/usdPhysics/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usdRender/pch.h b/pxr/usd/usdRender/pch.h
index 7802ec3e2d..e4dfaad4e0 100644
--- a/pxr/usd/usdRender/pch.h
+++ b/pxr/usd/usdRender/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usdRi/pch.h b/pxr/usd/usdRi/pch.h
index 905d2a1236..1b2e4fc255 100644
--- a/pxr/usd/usdRi/pch.h
+++ b/pxr/usd/usdRi/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usdShade/pch.h b/pxr/usd/usdShade/pch.h
index 698ab0ca65..8df6644f6a 100644
--- a/pxr/usd/usdShade/pch.h
+++ b/pxr/usd/usdShade/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usdSkel/pch.h b/pxr/usd/usdSkel/pch.h
index a4205ac46d..d2574d5cb9 100644
--- a/pxr/usd/usdSkel/pch.h
+++ b/pxr/usd/usdSkel/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usdUI/pch.h b/pxr/usd/usdUI/pch.h
index 47666439a2..3077d93203 100644
--- a/pxr/usd/usdUI/pch.h
+++ b/pxr/usd/usdUI/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usd/usdUtils/pch.h b/pxr/usd/usdUtils/pch.h
index 3a108ee5ef..723812b0cf 100644
--- a/pxr/usd/usdUtils/pch.h
+++ b/pxr/usd/usdUtils/pch.h
@@ -35,7 +35,7 @@
 #include <unistd.h>
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <glob.h>
 #include <limits.h>
 #include <sys/param.h>
diff --git a/pxr/usd/usdVol/pch.h b/pxr/usd/usdVol/pch.h
index 7802ec3e2d..e4dfaad4e0 100644
--- a/pxr/usd/usdVol/pch.h
+++ b/pxr/usd/usdVol/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usdImaging/plugin/usdShaders/pch.h b/pxr/usdImaging/plugin/usdShaders/pch.h
index 2037e25b8b..ab20c6ce76 100644
--- a/pxr/usdImaging/plugin/usdShaders/pch.h
+++ b/pxr/usdImaging/plugin/usdShaders/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usdImaging/usdAppUtils/pch.h b/pxr/usdImaging/usdAppUtils/pch.h
index 70b9602d5e..d21b305117 100644
--- a/pxr/usdImaging/usdAppUtils/pch.h
+++ b/pxr/usdImaging/usdAppUtils/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usdImaging/usdImaging/pch.h b/pxr/usdImaging/usdImaging/pch.h
index 35ea5620ec..87e9caf9d9 100644
--- a/pxr/usdImaging/usdImaging/pch.h
+++ b/pxr/usdImaging/usdImaging/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usdImaging/usdImagingGL/pch.h b/pxr/usdImaging/usdImagingGL/pch.h
index b9dfa7e416..9e835c50dc 100644
--- a/pxr/usdImaging/usdImagingGL/pch.h
+++ b/pxr/usdImaging/usdImagingGL/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usdImaging/usdRiImaging/pch.h b/pxr/usdImaging/usdRiImaging/pch.h
index 6ad2d403bb..0b57052e41 100644
--- a/pxr/usdImaging/usdRiImaging/pch.h
+++ b/pxr/usdImaging/usdRiImaging/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usdImaging/usdSkelImaging/pch.h b/pxr/usdImaging/usdSkelImaging/pch.h
index 69caaac23b..855b053899 100644
--- a/pxr/usdImaging/usdSkelImaging/pch.h
+++ b/pxr/usdImaging/usdSkelImaging/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usdImaging/usdVolImaging/pch.h b/pxr/usdImaging/usdVolImaging/pch.h
index 0fd54d571b..98c46bd330 100644
--- a/pxr/usdImaging/usdVolImaging/pch.h
+++ b/pxr/usdImaging/usdVolImaging/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/pxr/usdImaging/usdviewq/pch.h b/pxr/usdImaging/usdviewq/pch.h
index 1e55e66893..b6aca3bdef 100644
--- a/pxr/usdImaging/usdviewq/pch.h
+++ b/pxr/usdImaging/usdviewq/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
diff --git a/third_party/renderman-24/plugin/rmanArgsParser/pch.h b/third_party/renderman-24/plugin/rmanArgsParser/pch.h
index 63c182eb75..81690cc22e 100644
--- a/third_party/renderman-24/plugin/rmanArgsParser/pch.h
+++ b/third_party/renderman-24/plugin/rmanArgsParser/pch.h
@@ -30,7 +30,7 @@
 #if defined(ARCH_OS_DARWIN)
 #include <mach/mach_time.h>
 #endif
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_FREEBSD)
 #include <x86intrin.h>
 #endif
 #if defined(ARCH_OS_WINDOWS)
